forked from fossasia/badgemagic-firmware
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: save received data from BLE to flash
- Loading branch information
Showing
6 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
#include "ISP583.h" | ||
|
||
#include "data.h" | ||
#include "leddrv.h" | ||
|
||
uint32_t bigendian16_sum(uint16_t *s, int len) | ||
{ | ||
uint32_t sum = 0; | ||
while (len-- > 0) { | ||
sum += bswap16(s[len]); | ||
} | ||
return sum; | ||
} | ||
|
||
uint32_t data_flatSave(uint8_t *data, uint32_t len) | ||
{ | ||
uint32_t r = EEPROM_ERASE(0, len); | ||
if (r) | ||
return r; | ||
return EEPROM_WRITE(0, data, len); | ||
} | ||
|
||
uint16_t data_flash2newmem(uint8_t **chunk, uint32_t n) | ||
{ | ||
data_legacy_t header; | ||
EEPROM_READ(0, &header, LEGACY_HEADER_SIZE); | ||
|
||
uint16_t size = bswap16(header.sizes[n]) * LED_ROWS; | ||
if (size == 0) | ||
return 0; | ||
|
||
uint16_t offs = LEGACY_HEADER_SIZE | ||
+ bigendian16_sum(header.sizes, n) * LED_ROWS; | ||
|
||
*chunk = malloc(size); | ||
EEPROM_READ(offs, *chunk, size); | ||
return size; | ||
} | ||
|
||
static void __chunk2buffer(uint16_t *fb, uint8_t *chunk, int col) | ||
{ | ||
uint16_t tmpfb[8] = {0}; | ||
for (int i=0; i<8; i++) { | ||
for (int j=0; j<11; j++) { | ||
tmpfb[i] |= ((chunk[j] >> (7-i)) & 0x01) << j; | ||
} | ||
} | ||
for (int i=0; i<8; i++) { | ||
fb[col+i] = tmpfb[i]; | ||
} | ||
} | ||
|
||
void chunk2buffer(uint8_t *chunk, uint16_t size, uint16_t *buf) | ||
{ | ||
for (int i=0; i<size/11; i++) { | ||
__chunk2buffer(buf, &chunk[i*11], 8 * i); | ||
} | ||
} | ||
|
||
void chunk2fb(uint8_t *chunk, uint16_t size, fb_t *fb) | ||
{ | ||
chunk2buffer(chunk, size, fb->buf); | ||
} | ||
|
||
fb_t *chunk2newfb(uint8_t *chunk, uint16_t size) | ||
{ | ||
fb_t *fb = fb_new((size*8)/11); | ||
chunk2fb(chunk, size, fb); | ||
return fb; | ||
} | ||
|
||
fb_t *flash2newfb(uint32_t n) | ||
{ | ||
uint8_t *buf; | ||
uint16_t size = data_flash2newmem(&buf, n); | ||
if (size == 0) | ||
return NULL; | ||
return chunk2newfb(buf, size); | ||
free(buf); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#ifndef __DATA_H__ | ||
#define __DATA_H__ | ||
|
||
#include <stdint.h> | ||
|
||
#include "fb.h" | ||
|
||
typedef struct { | ||
uint8_t header[6]; | ||
uint8_t flash; | ||
uint8_t marquee; | ||
uint8_t modes[8]; | ||
|
||
uint16_t sizes[8]; // big endian | ||
|
||
uint8_t pad6[6]; | ||
uint8_t timestamp[6]; | ||
uint8_t pad4[4]; | ||
|
||
uint8_t separator[16]; | ||
|
||
uint8_t *bitmapdata; | ||
} data_legacy_t; | ||
|
||
#define LEGACY_TRANSFER_WIDTH (16) | ||
#define LEGACY_HEADER_SIZE (sizeof(data_legacy_t) - sizeof(uint8_t *)) | ||
|
||
static inline uint16_t bswap16(uint16_t i) { | ||
return (i >> 8) | (i << 8); | ||
} | ||
uint32_t bigendian16_sum(uint16_t *s, int len); | ||
|
||
uint32_t data_flatSave(uint8_t *data, uint32_t len); | ||
uint16_t data_flash2newmem(uint8_t **chunk, uint32_t n); | ||
|
||
void chunk2buffer(uint8_t *chunk, uint16_t size, uint16_t *buf); | ||
void chunk2fb(uint8_t *chunk, uint16_t size, fb_t *fb); | ||
|
||
fb_t *chunk2newfb(uint8_t *chunk, uint16_t size); | ||
fb_t *flash2newfb(uint32_t n); | ||
|
||
#endif /* __DATA_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef __RESET_H__ | ||
#define __RESET_H__ | ||
|
||
static inline void reset_jump() | ||
{ | ||
asm volatile("j 0x00"); | ||
} | ||
|
||
void poweroff(); | ||
|
||
#endif /* __RESET_H__ */ |