Page 2 of 3

Re: store calibration values

Posted: Wed Sep 26, 2012 10:37 am
by mobyfab
You can modify the memory requirements completely. (I guess there is a minimum)
It can even use static memory, no heap.

Re: store calibration values

Posted: Wed Sep 26, 2012 12:31 pm
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

Re: store calibration values

Posted: Wed Sep 26, 2012 1:31 pm
by mobyfab
Indeed, that would work on top of the abstract interface :)

Re: store calibration values

Posted: Sat Sep 29, 2012 3:20 pm
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.

Re: store calibration values

Posted: Sat Sep 29, 2012 3:49 pm
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

Re: [New Feature] store calibration values

Posted: Tue Oct 09, 2012 9:08 pm
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

Re: [New Feature] store calibration values

Posted: Tue Oct 23, 2012 3:40 am
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

Re: [New Feature] store calibration values

Posted: Fri Oct 26, 2012 3:16 pm
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)

Re: [New Feature] store calibration values

Posted: Fri Oct 26, 2012 6:36 pm
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

Re: [New Feature] store calibration values

Posted: Fri Oct 26, 2012 6:45 pm
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.