Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@shima-529
Created August 24, 2021 12:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shima-529/9f44f83b7cb9aebcd6f8a1aa55592893 to your computer and use it in GitHub Desktop.
Save shima-529/9f44f83b7cb9aebcd6f8a1aa55592893 to your computer and use it in GitHub Desktop.
#include <stdint.h>
#include "i2c.h"
// Blink 4Hz
static const uint8_t gp_nvmdata[] = {
#include "../../blink.array"
};
#define GP_CONTROL_CODE (0x01 << 4)
void gp_erase(void) {
for(int i = 0; i < 16; i++) {
uint8_t dat[] = {
0xE3, // Erase Command Register
0x80 | i // Page Address
};
i2c_send(GP_CONTROL_CODE | 0x02, dat, 2, 20);
}
}
void gp_reg_write(void) {
for(int i = 0; i < 16; i++) {
uint8_t dat[1 + 16] = {i * 16};
for(int j = 0; j < 16; j++) {
dat[1 + j] = gp_nvmdata[i * 16 + j];
}
i2c_send(GP_CONTROL_CODE | 0x02, dat, 1 + 16, 20); // Write
}
}
void gp_nvm_write(void) {
for(int i = 0; i < 16; i++) {
uint8_t dat[1 + 16] = {i * 16};
for(int j = 0; j < 16; j++) {
dat[1 + j] = gp_nvmdata[i * 16 + j];
}
i2c_send(GP_CONTROL_CODE | 0x04, dat, 1 + 16, 20); // Write
}
}
void gp_invoke_por(void) {
uint8_t dat[] = {0xC8, 2};
i2c_send(GP_CONTROL_CODE | 0x02, dat, 2, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment