This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to change c++ code into NORDIC nRF52832

Hi,

I want to write or change the code in to nRF52832

I have some code this code i should write for nRF52832

kindly give any suggestion

here is the my code

uint8_t HT1632_LedMatrix::putChar(int x, int y, char c) {
  // fonts defined for ascii 32 and beyond (index 0 in font array is ascii 32);
  // CGRAM characters are in range 0 to 15 with 8-15 being repeat of 0-7
  // note we force y to be modulo 8 - we do not support writing character to partial y values.
 
  uint8_t charIndex;
  uint8_t colData;
  uint8_t numCols;
  uint8_t chipno;
  uint8_t addr;
  uint8_t colsLeft = 0;        // cols that didn't fit
 
  if( c > 15 ) {
    // Regular characters
    // replace undisplayable characters with blank;
    if (c < 32 || c > 126) {
            charIndex = 0;
    } else {
            charIndex = c - 32;
    }
 
    // move character definition, pixel by pixel, onto the display;
    // fonts are defined as one byte per col;
    numCols=smallFont[charIndex][6];   // get the number of columns this character uses
    for (uint8_t col=0; col<numCols; col++) {
            colData = smallFont[charIndex][col];
        chipno = chip_number(x,y);
        addr = chip_byte_address(x,y); // compute which memory byte this is in
        if (x <= xMax && y <= yMax) {
            shadowram[(addr>>1)+32*chipno] = colData;
            sendcol(chipno,addr,colData);
            x++;
        } else {
            colsLeft++;
        }
    }
  } else {
    // CGRAM Characters
    charIndex = c & 0x07;       // Only low 3 bits count
    numCols=cgram[charIndex][0];    // get the number of columns this character uses
    // fonts are defined as one byte per col;
        for (uint8_t col=1; col<=numCols; col++) {
            colData = cgram[charIndex][col];
        chipno = chip_number(x,y);
        addr = chip_byte_address(x,y); // compute which memory byte this is in
        if (x <= xMax && y <= yMax) {
            shadowram[(addr>>1)+32*chipno] = colData;
            sendcol(chipno,addr,colData);
            x++;
        } else {
            colsLeft++;
        }
    }
  }
 
  cursorX = x;
  cursorY = y;
 
  return colsLeft;
}
Parents Reply Children
  • Exactly the same as would be required to convert any other C++ code to C - the languages are standard; not specific to Nordic.

    But the function seems to be only using 'C' syntax anyhow - apart from the initial

    uint8_t HT1632_LedMatrix::putChar(int x, int y, char c) {

    So you could start by just changing that to a standard 'C' function signature; eg,

    uint8_t HT1632_LedMatrix_putChar(int x, int y, char c) {

  • Probably not quite as it uses variables like cgram and functions such as chip_byte_address() which I assume are member variables and methods, unless they are globals which is not so likely. 

    However if he defines HT1632_LedMatrix_putChar() as you have above but with an initial HT1632_LedMatrix pointer, as extern "C", and then calls through the pointer it effectively renames the function into something callable from C, you just drag the pointer about. 

    However I'm not sure I understand the original question at all and the answer 'no changes are required' is the right one. 

  • it uses variables like cgram and functions such as chip_byte_address()

    But it's only accessing those things using standard 'C' syntax....

    Of course, any & all external references would have to be satisfied.

    I'm not sure I understand the original question at all

    likewise:

    Not sure what you're actually asking here
  • Using C syntax (ie no x.method()) however it's in a C++ method definition so they are most probably instance members or methods of the class. eg send_col() is just called with no object instance, however it's an instance method of the class (I just googled for the code) so that's implicitly this->send_col(), the this-> is inferred. So you can't flatten the code, you need the object reference. 

  • you can't flatten the code

    Well, you can - but there'll be an amount of work to it!

    As has already been pointed out to , it's not about nRF - it's all just standard language stuff.

Related