[New Feature] store calibration values

mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: store calibration values

Post by mobyfab »

You can modify the memory requirements completely. (I guess there is a minimum)
It can even use static memory, no heap.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: store calibration values

Post by Giovanni »

The idea is to create an abstract interface for file system, Mabl's wrapper could (and probably will if Mabl agrees) be used as part of the implementation.

Giovanni
mobyfab
Posts: 484
Joined: Sat Nov 19, 2011 6:47 pm
Has thanked: 21 times
Been thanked: 31 times

Re: store calibration values

Post by mobyfab »

Indeed, that would work on top of the abstract interface :)
mabl
Posts: 417
Joined: Tue Dec 21, 2010 10:19 am
Been thanked: 1 time

Re: store calibration values

Post by mabl »

Giovanni wrote:The idea is to create an abstract interface for file system, Mabl's wrapper could (and probably will if Mabl agrees) be used as part of the implementation.


Sure, feel free to use the code.

In my own projects I use an abstraction based on minini ( http://code.google.com/p/minini/ ) - works great.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: store calibration values

Post by Giovanni »

This minini is exactly what is needed IMO. I will proceed with the FS abstraction layer then we will discuss about implementations and upper layers.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: [New Feature] store calibration values

Post by Tectu »

At this point, I'd like to publisha few lines of code, how I store the calibration struct on an SD card. The code is pretty basic and not that professional. It simply creates a new file «calibration» and stores the 16 bytes of the struct in it.

Code: Select all

void lld_tpWriteCalibration(struct cal cal) {
    FRESULT ferr;
    FIL fi;
    UINT wr;
   
        ferr = f_open(&fi, "calibration", FA_CREATE_ALWAYS | FA_WRITE);
    if(ferr != FR_OK) {
                #if DEBUG
                chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't open file!\r\n");
        chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
                return;
                #endif
        }

    ferr = f_write(&fi, &cal, sizeof(struct cal), &wr);
    if(ferr != FR_OK) {
        #if DEBUG
        chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't write file!\r\n");
        chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
                return;
        #endif
    }
       
    ferr = f_close(&fi);
    if(ferr != FR_OK) {
        #if DEBUG
        chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't close file!\r\n");
                chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
                return;
        #endif
    }
}

struct cal lld_tpReadCalibration(void) {
    FRESULT ferr;
    FIL fi;
    UINT br;
    uint8_t i;
        struct cal cal = { 1, 1, 0, 0 };

    ferr = f_open(&fi, "calibration", FA_READ);
    if(ferr != FR_OK) {
                #if DEBUG
                chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't open file!\r\n");
                chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
                #endif
        return cal;
        }

    ferr = f_read(&fi, &cal, sizeof(struct cal), &br);
    if(ferr != FR_OK) {
        #if DEBUG
        chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't read file!\r\n");
        chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
                #endif
        return cal;
    }

    ferr = f_close(&fi);
    if(ferr != FR_OK) {
        #if DEBUG
        chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't close file!\r\n");
        chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
                #endif
        return cal;
    }

        #if DEBUG
        if(cal.xm != 1 && cal.ym != 1 && cal.xn != 0 && cal.yn != 0)  // check if default or different values
                chprintf(DEBUG_SERIAL, "calibration restored from SD card\r\n");
        #endif

    return cal;
}



~ Tectu
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: [New Feature] store calibration values

Post by Tectu »

I could finally implement the first version of a usable storage interface, without using streams yet: http://chibios-gfx.com/documentation/to ... alibration


~ Tectu
tinito
Posts: 112
Joined: Tue Jun 07, 2011 10:32 am
Has thanked: 1 time
Been thanked: 1 time

Re: [New Feature] store calibration values

Post by tinito »

I'm interested in some static storage too, i would use the EEMUL approach but abstracting the storage media would for sure the best option.

About Tectu code: shouldn't you free the allocated memory and return NULL instead of doing cal = NULL and returning cal? (BTW I would definitively allocate the memory outside that function and pass the pointer)
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: [New Feature] store calibration values

Post by Tectu »

Hello tinito,

Please note that the storage calibration interface has changed. THe new one is working with pointers ;-)
Her you can find the new one: http://chibios-gfx.com/documentation/touchpad/calibration


~ Tectu
tinito
Posts: 112
Joined: Tue Jun 07, 2011 10:32 am
Has thanked: 1 time
Been thanked: 1 time

Re: [New Feature] store calibration values

Post by tinito »

Hi Tectu,

I was looking to the same version, and I think this code

Code: Select all

    cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
 
    ferr = wf_open(&fi, "calib", FA_READ);
    if(ferr != FR_OK) {
          cal = NULL;
   return cal;
    }


should be something like

Code: Select all

    cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
 
    ferr = wf_open(&fi, "calib", FA_READ);
    if(ferr != FR_OK) {
          chHeapFree(cal);
   return NULL;
    }


and the same for every error condition, to free the unused memory.
Locked