Alvee Ahmed
/
Hobbyking_Cheetah_Compact_DRV8323_14bit
customizing code for Aliexpress 14 bit version with MA702
PreferenceWriter/PrefrenceWriter.cpp@23:2adf23ee0305, 2017-04-05 (annotated)
- Committer:
- benkatz
- Date:
- Wed Apr 05 20:54:16 2017 +0000
- Revision:
- 23:2adf23ee0305
- Child:
- 24:58c2d7571207
Added bayley's flash writer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
benkatz | 23:2adf23ee0305 | 1 | #include "PreferenceWriter.h" |
benkatz | 23:2adf23ee0305 | 2 | #include "FlashWriter.h" |
benkatz | 23:2adf23ee0305 | 3 | #include "user_config.h" |
benkatz | 23:2adf23ee0305 | 4 | #include "mbed.h" |
benkatz | 23:2adf23ee0305 | 5 | |
benkatz | 23:2adf23ee0305 | 6 | PreferenceWriter::PreferenceWriter(uint32_t sector) { |
benkatz | 23:2adf23ee0305 | 7 | writer = new FlashWriter(sector); |
benkatz | 23:2adf23ee0305 | 8 | __sector = sector; |
benkatz | 23:2adf23ee0305 | 9 | __ready = false; |
benkatz | 23:2adf23ee0305 | 10 | } |
benkatz | 23:2adf23ee0305 | 11 | |
benkatz | 23:2adf23ee0305 | 12 | void PreferenceWriter::open() { |
benkatz | 23:2adf23ee0305 | 13 | writer->open(); |
benkatz | 23:2adf23ee0305 | 14 | __ready = true; |
benkatz | 23:2adf23ee0305 | 15 | } |
benkatz | 23:2adf23ee0305 | 16 | |
benkatz | 23:2adf23ee0305 | 17 | bool PreferenceWriter::ready() { |
benkatz | 23:2adf23ee0305 | 18 | return __ready; |
benkatz | 23:2adf23ee0305 | 19 | } |
benkatz | 23:2adf23ee0305 | 20 | |
benkatz | 23:2adf23ee0305 | 21 | void PreferenceWriter::write(int x, int index) { |
benkatz | 23:2adf23ee0305 | 22 | __int_reg[index] = x; |
benkatz | 23:2adf23ee0305 | 23 | } |
benkatz | 23:2adf23ee0305 | 24 | |
benkatz | 23:2adf23ee0305 | 25 | void PreferenceWriter::write(float x, int index) { |
benkatz | 23:2adf23ee0305 | 26 | __float_reg[index] = x; |
benkatz | 23:2adf23ee0305 | 27 | } |
benkatz | 23:2adf23ee0305 | 28 | |
benkatz | 23:2adf23ee0305 | 29 | void PreferenceWriter::flush() { |
benkatz | 23:2adf23ee0305 | 30 | int offs; |
benkatz | 23:2adf23ee0305 | 31 | for (offs = 0; offs < 256; offs++) { |
benkatz | 23:2adf23ee0305 | 32 | writer->write(offs, __int_reg[offs]); |
benkatz | 23:2adf23ee0305 | 33 | } |
benkatz | 23:2adf23ee0305 | 34 | for (; offs < 320; offs++) { |
benkatz | 23:2adf23ee0305 | 35 | writer->write(offs, __float_reg[offs - 256]); |
benkatz | 23:2adf23ee0305 | 36 | } |
benkatz | 23:2adf23ee0305 | 37 | } |
benkatz | 23:2adf23ee0305 | 38 | |
benkatz | 23:2adf23ee0305 | 39 | void PreferenceWriter::load() { |
benkatz | 23:2adf23ee0305 | 40 | int offs; |
benkatz | 23:2adf23ee0305 | 41 | for (offs = 0; offs < 256; offs++) { |
benkatz | 23:2adf23ee0305 | 42 | __int_reg[offs] = flashReadInt(__sector, offs); |
benkatz | 23:2adf23ee0305 | 43 | } |
benkatz | 23:2adf23ee0305 | 44 | for(; offs < 320; offs++) { |
benkatz | 23:2adf23ee0305 | 45 | __float_reg[offs - 256] = flashReadFloat(__sector, offs); |
benkatz | 23:2adf23ee0305 | 46 | } |
benkatz | 23:2adf23ee0305 | 47 | } |
benkatz | 23:2adf23ee0305 | 48 | |
benkatz | 23:2adf23ee0305 | 49 | void PreferenceWriter::close() { |
benkatz | 23:2adf23ee0305 | 50 | writer->close(); |
benkatz | 23:2adf23ee0305 | 51 | } |