Skip to content

Commit

Permalink
Add check for flashing via esptool.py
Browse files Browse the repository at this point in the history
  • Loading branch information
renzenicolai committed Jul 5, 2022
1 parent 4fd7d44 commit 971c375
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
22 changes: 15 additions & 7 deletions i2c_peripheral.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@ static bool webusb_interrupt = false;

static int ir_statemachine = -1;

struct {
static struct {
uint8_t registers[256];
bool modified[256];
uint8_t address;
bool write_in_progress;
} i2c_registers;

uint8_t i2c_controlled_gpios[] = {SAO_IO0_PIN, SAO_IO1_PIN, PROTO_0_PIN, PROTO_1_PIN};
uint8_t input1_gpios[] = {BUTTON_HOME, BUTTON_MENU, BUTTON_START, BUTTON_ACCEPT, BUTTON_BACK, FPGA_CDONE};
uint8_t input2_gpios[] = {BUTTON_JOY_A, BUTTON_JOY_B, BUTTON_JOY_C, BUTTON_JOY_D, BUTTON_JOY_E};
static const uint8_t i2c_controlled_gpios[] = {SAO_IO0_PIN, SAO_IO1_PIN, PROTO_0_PIN, PROTO_1_PIN};
static const uint8_t input1_gpios[] = {BUTTON_HOME, BUTTON_MENU, BUTTON_START, BUTTON_ACCEPT, BUTTON_BACK, FPGA_CDONE};
static const uint8_t input2_gpios[] = {BUTTON_JOY_A, BUTTON_JOY_B, BUTTON_JOY_C, BUTTON_JOY_D, BUTTON_JOY_E};

static absolute_time_t next_adc_read;
uint8_t next_adc_channel;
static uint8_t next_adc_channel;

const bool i2c_registers_read_only[256] = {
static const bool i2c_registers_read_only[256] = {
true, false, true, false, false, false, true, true, // 0-7
true, true, false, true, true, true, true, true, // 8-15
false, false, false, false, false, false, false, false, // 16-23
false, false, true, false, false, true, true, true, // 16-23
true, true, true, true, true, true, true, true, // 24-31
false, false, false, false, false, false, false, false, // 32-39
false, false, false, false, false, false, false, false, // 40-47
Expand Down Expand Up @@ -342,3 +342,11 @@ void i2c_set_webusb_mode(uint8_t mode) {
}

void i2c_set_crash_debug_state(bool crashed, bool debug) { i2c_registers.registers[I2C_REGISTER_CRASH_DEBUG] = (crashed & 1) | ((debug << 1) & 2); }

void i2c_set_reset_attempted(bool attempted) {
i2c_registers.registers[I2C_REGISTER_RESET_ATTEMPTED] = attempted;
}

bool i2c_get_reset_allowed() {
return !i2c_registers.registers[I2C_REGISTER_RESET_LOCK];
}
7 changes: 5 additions & 2 deletions i2c_peripheral.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ void i2c_set_webusb_mode(uint8_t mode);

void i2c_set_crash_debug_state(bool crashed, bool debug);

void i2c_set_reset_attempted(bool attempted);
bool i2c_get_reset_allowed();

enum {
// 0-7
I2C_REGISTER_FW_VER,
Expand All @@ -46,8 +49,8 @@ enum {
I2C_REGISTER_BL_TRIGGER,
I2C_REGISTER_WEBUSB_MODE,
I2C_REGISTER_CRASH_DEBUG,
I2C_REGISTER_RESERVED2,
I2C_REGISTER_RESERVED3,
I2C_REGISTER_RESET_LOCK,
I2C_REGISTER_RESET_ATTEMPTED,
I2C_REGISTER_CHARGING_STATE,
I2C_REGISTER_ADC_VALUE_TEMP_LO,
I2C_REGISTER_ADC_VALUE_TEMP_HI,
Expand Down
7 changes: 6 additions & 1 deletion uart_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,12 @@ void tud_cdc_line_state_cb(uint8_t itf, bool dtr, bool rts) {
if ((esp32_reset_state == 1) && (dtr2) && (!rts2)) esp32_reset_state = 2;
if ((esp32_reset_state == 2) && (!dtr2) && (rts2)) esp32_reset_state = 3;
if ((esp32_reset_state == 3) && (dtr2) && (rts2)) {
esp32_reset(true);
if (i2c_get_reset_allowed()) {
esp32_reset(true);
} else {
i2c_set_reset_attempted(true);
esp32_reset(false);
}
}

if ((esp32_reset_app_state == 0) && ((!dtr2) && rts2)) esp32_reset_app_state = 1;
Expand Down

0 comments on commit 971c375

Please sign in to comment.