From 96058f06c28e4d8c94de2f42a2874b25ffc167c5 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Wed, 30 Dec 2020 03:30:15 +0100 Subject: [PATCH] Changed address of keyboard device and added reboot command to i2c upload --- Src/control.c | 11 ++++++----- Src/firmware.c | 10 ++++++++-- Src/main.c | 4 ++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Src/control.c b/Src/control.c index a55c551..2de5ac4 100644 --- a/Src/control.c +++ b/Src/control.c @@ -114,15 +114,16 @@ void handle_io_read() { /* write_data(0x01); */ /* break; */ - // Stand in for the keyboard hardware + /* Stand in for the keyboard hardware */ /* case 0x1E: */ - /* write_data(control.input.c); */ - /* control.input.received = 0; */ + /* write_data(char_c); */ + /* char_r = 0; */ /* break; */ - // Stand in for the keyboard hardware + /* Stand in for the keyboard hardware */ /* case 0x1F: */ - /* write_data(0x01 * control.input.received); */ + /* #<{(| write_data(0x01 * char_r); |)}># */ + /* write_data(0x00); */ /* break; */ case 0x08: diff --git a/Src/firmware.c b/Src/firmware.c index 05a9073..384542a 100644 --- a/Src/firmware.c +++ b/Src/firmware.c @@ -43,9 +43,15 @@ void firmware_update() { control_program_eeprom(data, length); break; case TARGET_I2C: { - // Make sure tell the device to enter bootloader mode first - // Upload the application + printf("Restarting target to bootloader...\n\r"); + // @todo Make sure that the address to reset to bootloader is the same as the bootloader address + uint8_t reboot_command[] = {0x07}; + HAL_I2C_Master_Transmit(&hi2c1, address << 1, reboot_command, sizeof(reboot_command), 1000); + + for (volatile int i = 0; i < 10000000; ++i) {} + printf("Uploading to target...\n\r"); + uint8_t upload_command[4 + length]; upload_command[0] = 0x02; upload_command[1] = 0x01; diff --git a/Src/main.c b/Src/main.c index 2a183b6..ee7c286 100644 --- a/Src/main.c +++ b/Src/main.c @@ -123,7 +123,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (!is_command) { // ONLY SEND THE FIRST CHAR if (cmd_buffer_len > 0) { - HAL_I2C_Master_Transmit(&hi2c1, 0x04 << 1, &byte, 1, 1000); + HAL_I2C_Master_Transmit(&hi2c1, 0x29 << 1, &byte, 1, 1000); } cmd_buffer_len = 0; } else if (handle_command && is_command) { @@ -148,7 +148,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { break; case '#': - HAL_I2C_Master_Transmit(&hi2c1, 0x04 << 1, &byte, 1, 1000); + HAL_I2C_Master_Transmit(&hi2c1, 0x29 << 1, &byte, 1, 1000); break; default: