From 165abf36902ae52ceb9190eac4545f5661829055 Mon Sep 17 00:00:00 2001 From: lcgamboa Date: Thu, 19 Jan 2023 22:43:55 -0300 Subject: [PATCH] fix: Fix stm32 qemu afio map use in PICSimLab !minor --- src/boards/board_Arduino_Mega.cc | 4 +- src/boards/board_Arduino_Nano.cc | 4 +- src/boards/board_Blue_Pill.cc | 142 +++++++++++++++++++++++++++---- src/boards/board_DevKitC.cc | 44 +++++++++- src/boards/board_STM32_H103.cc | 142 +++++++++++++++++++++++++++---- src/boards/bsim_qemu.cc | 9 +- src/boards/bsim_ucsim.cc | 4 +- src/devices/bitbang_i2c.cc | 10 +-- src/devices/bitbang_i2c.h | 2 +- src/devices/bitbang_spi.cc | 4 +- src/devices/bitbang_spi.h | 2 +- src/devices/bitbang_uart.cc | 3 +- src/devices/bitbang_uart.h | 2 +- 13 files changed, 310 insertions(+), 62 deletions(-) diff --git a/src/boards/board_Arduino_Mega.cc b/src/boards/board_Arduino_Mega.cc index 47f8eb85..b8330d37 100644 --- a/src/boards/board_Arduino_Mega.cc +++ b/src/boards/board_Arduino_Mega.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2015-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2015-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,6 +65,6 @@ void cboard_Arduino_Mega::ReadPreferences(char* name, char* value) { } } -// TODO cboard_Arduino_Mega: add suport to anaolog inputs A6 and A7 +// TODO cboard_Arduino_Mega: add suport to analog inputs A6 and A7 board_init(BOARD_Arduino_Mega_Name, cboard_Arduino_Mega); diff --git a/src/boards/board_Arduino_Nano.cc b/src/boards/board_Arduino_Nano.cc index 4263b6ea..b8516325 100644 --- a/src/boards/board_Arduino_Nano.cc +++ b/src/boards/board_Arduino_Nano.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2015-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2015-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -66,6 +66,6 @@ void cboard_Arduino_Nano::ReadPreferences(char* name, char* value) { } } -// TODO cboard_Arduino_Nano: add suport to anaolog inputs A6 and A7 +// TODO cboard_Arduino_Nano: add suport to analog inputs A6 and A7 board_init(BOARD_Arduino_Nano_Name, cboard_Arduino_Nano); diff --git a/src/boards/board_Blue_Pill.cc b/src/boards/board_Blue_Pill.cc index be45c8c4..6d4020cc 100644 --- a/src/boards/board_Blue_Pill.cc +++ b/src/boards/board_Blue_Pill.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2015-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2015-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -80,16 +80,14 @@ cboard_Blue_Pill::cboard_Blue_Pill(void) { Proc = "stm32f103c8t6"; // default microcontroller if none defined in preferences ReadMaps(); // Read input and output board maps - // TODO read pin configuration from registers instead use fixed pins - master_i2c[0].scl_pin = 42; // pb6 or pb8 - master_i2c[0].sda_pin = 43; // pb7 or pb9 - master_i2c[1].scl_pin = 21; // pb10 - master_i2c[1].sda_pin = 22; // pb11 + master_i2c[0].scl_pin = 0; + master_i2c[0].sda_pin = 0; + master_i2c[1].scl_pin = 0; + master_i2c[1].sda_pin = 0; - // TODO read pin configuration from registers instead use fixed pins - master_spi[0].sck_pin = 15; // pa5 - master_spi[0].copi_pin = 17; // pa7 - master_spi[0].cipo_pin = 16; // pa6 + master_spi[0].sck_pin = 0; + master_spi[0].copi_pin = 0; + master_spi[0].cipo_pin = 0; master_spi[0].cs_pin[0] = 0; master_spi[0].cs_pin[1] = 0; master_spi[0].cs_pin[2] = 0; @@ -101,13 +99,12 @@ cboard_Blue_Pill::cboard_Blue_Pill(void) { master_spi[1].cs_pin[1] = 0; master_spi[1].cs_pin[2] = 0; - // TODO read pin configuration from registers instead use fixed pins - master_uart[0].tx_pin = 30; // pa9 - master_uart[0].rx_pin = 31; // pa10 - master_uart[1].tx_pin = 12; // pa2 - master_uart[1].rx_pin = 13; // pa3 - master_uart[2].tx_pin = 21; // pb10 - master_uart[2].rx_pin = 22; // pb11 + master_uart[0].tx_pin = 0; + master_uart[0].rx_pin = 0; + master_uart[1].tx_pin = 0; + master_uart[1].rx_pin = 0; + master_uart[2].tx_pin = 0; + master_uart[2].rx_pin = 0; // label1 label1 = new CLabel(); @@ -621,7 +618,116 @@ void cboard_Blue_Pill::MSetAPin(int pin, float value) { } } -void cboard_Blue_Pill::PinsExtraConfig(int cfg) {} +void cboard_Blue_Pill::PinsExtraConfig(int cfg) { + if ((cfg & 0x8008) == 0x8008) { // Alternate function + int pin = (cfg & 0x7FF0) >> 4; + int port = cfg & 0x0003; + uint32_t* uart_afio; + // int cfg_ = (cfg & 0x000C) >> 2; + // printf("Extra CFG port(%i) pin[%02i]=0x%02X \n", port, pin, cfg_); + + switch (port) { + case 0: // GPIOA + switch (pin) { + case 2: // uart2 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 15); + if (!(*uart_afio)) { + master_uart[1].ctrl_on = 1; + master_uart[1].tx_pin = 12; // pa2 + master_uart[1].rx_pin = 13; // pa3 + } + break; + case 5: + case 6: + case 7: // spi1 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 53); + if (!(*uart_afio)) { + master_spi[0].ctrl_on = 1; + master_spi[0].sck_pin = 15; // pa5 + master_spi[0].copi_pin = 17; // pa7 + master_spi[0].cipo_pin = 16; // pa6 + } + break; + case 9: // uart1 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 14); + if (!(*uart_afio)) { + master_uart[0].ctrl_on = 1; + master_uart[0].tx_pin = 30; // pa9 + master_uart[0].rx_pin = 31; // pa10 + } + break; + } + break; + case 1: // GPIOB + switch (pin) { + case 3: + case 4: + case 5: // spi1 (alt) + uart_afio = qemu_picsimlab_get_internals(0x1000 | 53); + if (!(*uart_afio)) { + master_spi[0].ctrl_on = 1; + master_spi[0].sck_pin = 39; // pb3 + master_spi[0].copi_pin = 41; // pb5 + master_spi[0].cipo_pin = 40; // pb4 + } + break; + case 6: // uart1 (alt) and i2c + uart_afio = qemu_picsimlab_get_internals(0x1000 | 14); + if ((*uart_afio)) { + master_uart[0].ctrl_on = 1; + master_uart[0].tx_pin = 42; // pb6 + master_uart[0].rx_pin = 43; // pb7 + } + // break; + case 7: // i2c0 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 42); + if (!(*uart_afio)) { + master_i2c[0].ctrl_on = 1; + master_i2c[0].scl_pin = 42; // pb6 + master_i2c[0].sda_pin = 43; // pb7 + } + break; + case 8: + case 9: // i2c0 (alt) + uart_afio = qemu_picsimlab_get_internals(0x1000 | 42); + if ((*uart_afio)) { + master_i2c[0].ctrl_on = 1; + master_i2c[0].scl_pin = 45; // pb8 + master_i2c[0].sda_pin = 46; // pb9 + } + break; + case 10: // uart3 + /* + uart_afio = qemu_picsimlab_get_internals(0x1000 | 16); + if (!(*uart_afio)) { + master_uart[2].ctrl_on = 1; + master_uart[2].tx_pin = 21; // pb10 + master_uart[2].rx_pin = 22; // pb11 + } + */ + case 11: // i2c1 + master_i2c[1].ctrl_on = 1; + master_i2c[1].scl_pin = 21; // pb10 + master_i2c[1].sda_pin = 22; // pb11 + break; + + case 13: + case 14: + case 15: // spi2 + master_spi[1].ctrl_on = 1; + master_spi[1].sck_pin = 26; // pb13 + master_spi[1].copi_pin = 28; // pb15 + master_spi[1].cipo_pin = 27; // pb14 + break; + } + break; + case 2: // GPIOC + break; + case 3: // GPIOD + break; + } + } +} // Register the board in PICSimLab board_init(BOARD_Blue_Pill_Name, cboard_Blue_Pill); diff --git a/src/boards/board_DevKitC.cc b/src/boards/board_DevKitC.cc index 4b53f631..89ae043e 100644 --- a/src/boards/board_DevKitC.cc +++ b/src/boards/board_DevKitC.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2021-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2021-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -777,35 +777,44 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) { switch (function) { case 9: // HSPIQ + master_spi[0].ctrl_on = 1; master_spi[0].cipo_pin = io2pin(gpio); break; case 14: // U0RXD + master_uart[0].ctrl_on = 1; master_uart[0].rx_pin = io2pin(gpio); break; case 17: // U1RXD + master_uart[1].ctrl_on = 1; master_uart[1].rx_pin = io2pin(gpio); break; case 29: // I2CEXT0_SCL + master_i2c[0].ctrl_on = 1; master_i2c[0].scl_pin = io2pin(gpio); break; case 30: // I2CEXT0_SDA + master_i2c[0].ctrl_on = 1; master_i2c[0].sda_pin = io2pin(gpio); break; case 64: // VSPIQ + master_spi[1].ctrl_on = 1; master_spi[1].cipo_pin = io2pin(gpio); break; case 95: // I2CEXT1_SCL + master_i2c[1].ctrl_on = 1; master_i2c[1].scl_pin = io2pin(gpio); break; case 96: // I2CEXT1_SDA + master_i2c[1].ctrl_on = 1; master_i2c[1].sda_pin = io2pin(gpio); break; case 198: // U2RXD + master_uart[2].ctrl_on = 1; master_uart[2].rx_pin = io2pin(gpio); break; } @@ -821,66 +830,85 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) { switch (function) { case 8: // HSPICLK + master_spi[0].ctrl_on = 1; master_spi[0].sck_pin = io2pin(gpio); break; case 9: // HSPIQ + master_spi[0].ctrl_on = 1; master_spi[0].cipo_pin = io2pin(gpio); break; case 10: // HSPID + master_spi[0].ctrl_on = 1; master_spi[0].copi_pin = io2pin(gpio); break; case 11: // HSPICS0 + master_spi[0].ctrl_on = 1; master_spi[0].cs_pin[0] = io2pin(gpio); break; case 14: // U0TXD + master_uart[0].ctrl_on = 1; master_uart[0].tx_pin = io2pin(gpio); break; case 17: // U1TXD + master_uart[1].ctrl_on = 1; master_uart[1].tx_pin = io2pin(gpio); break; case 29: // I2CEXT0_SCL + master_i2c[0].ctrl_on = 1; master_i2c[0].scl_pin = io2pin(gpio); break; case 30: // I2CEXT0_SDA + master_i2c[0].ctrl_on = 1; master_i2c[0].sda_pin = io2pin(gpio); break; case 61: // HSPICS1 + master_spi[0].ctrl_on = 1; master_spi[0].cs_pin[1] = io2pin(gpio); break; case 62: // HSPICS2 + master_spi[0].ctrl_on = 1; master_spi[0].cs_pin[2] = io2pin(gpio); break; case 63: // VSPICLK + master_spi[1].ctrl_on = 1; master_spi[1].sck_pin = io2pin(gpio); break; case 64: // VSPIQ + master_spi[1].ctrl_on = 1; master_spi[1].cipo_pin = io2pin(gpio); break; case 65: // VSPID + master_spi[1].ctrl_on = 1; master_spi[1].copi_pin = io2pin(gpio); break; case 68: // VSPICS0 + master_spi[1].ctrl_on = 1; master_spi[1].cs_pin[0] = io2pin(gpio); break; case 69: // VSPICS1 + master_spi[1].ctrl_on = 1; master_spi[1].cs_pin[1] = io2pin(gpio); break; case 70: // VSPICS2 + master_spi[1].ctrl_on = 1; master_spi[1].cs_pin[2] = io2pin(gpio); break; case 95: // I2CEXT1_SCL + master_i2c[1].ctrl_on = 1; master_i2c[1].scl_pin = io2pin(gpio); break; case 96: // I2CEXT1_SDA + master_i2c[1].ctrl_on = 1; master_i2c[1].sda_pin = io2pin(gpio); break; case 198: // U2RTXD + master_uart[2].ctrl_on = 1; master_uart[2].tx_pin = io2pin(gpio); break; } @@ -897,9 +925,11 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) { case 0: switch (gpio) { case 1: + master_uart[0].ctrl_on = 1; master_uart[0].tx_pin = IO1; break; case 3: + master_uart[0].ctrl_on = 1; master_uart[0].rx_pin = IO3; break; } @@ -907,27 +937,35 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) { case 1: switch (gpio) { case 12: + master_spi[0].ctrl_on = 1; master_spi[0].cipo_pin = IO12; break; case 13: + master_spi[0].ctrl_on = 1; master_spi[0].copi_pin = IO13; break; case 14: + master_spi[0].ctrl_on = 1; master_spi[0].sck_pin = IO14; break; case 15: + master_spi[0].ctrl_on = 1; master_spi[0].cs_pin[0] = IO15; break; case 18: + master_spi[1].ctrl_on = 1; master_spi[1].sck_pin = IO18; break; case 19: + master_spi[1].ctrl_on = 1; master_spi[1].cipo_pin = IO19; break; case 23: + master_spi[1].ctrl_on = 1; master_spi[1].copi_pin = IO23; break; case 5: + master_spi[1].ctrl_on = 1; master_spi[1].cs_pin[0] = IO5; break; } @@ -939,15 +977,19 @@ void cboard_DevKitC::PinsExtraConfig(int cfg) { case 4: switch (gpio) { case 9: + master_uart[1].ctrl_on = 1; master_uart[1].rx_pin = IO9; break; case 10: + master_uart[1].ctrl_on = 1; master_uart[1].tx_pin = IO10; break; case 16: + master_uart[2].ctrl_on = 1; master_uart[2].rx_pin = IO16; break; case 17: + master_uart[2].ctrl_on = 1; master_uart[2].tx_pin = IO17; break; } diff --git a/src/boards/board_STM32_H103.cc b/src/boards/board_STM32_H103.cc index 80602d6f..4d11aa7f 100644 --- a/src/boards/board_STM32_H103.cc +++ b/src/boards/board_STM32_H103.cc @@ -87,16 +87,14 @@ cboard_STM32_H103::cboard_STM32_H103(void) { ReadMaps(); // Read input and output board maps p_BUT = 0; - // TODO read pin configuration from registers instead use fixed pins - master_i2c[0].scl_pin = 58; // pb6 or pb8 - master_i2c[0].sda_pin = 59; // pb7 or pb9 - master_i2c[1].scl_pin = 29; // pb10 - master_i2c[1].sda_pin = 30; // pb11 - - // TODO read pin configuration from registers instead use fixed pins - master_spi[0].sck_pin = 21; // pa5 - master_spi[0].copi_pin = 23; // pa7 - master_spi[0].cipo_pin = 22; // pa6 + master_i2c[0].scl_pin = 0; + master_i2c[0].sda_pin = 0; + master_i2c[1].scl_pin = 0; + master_i2c[1].sda_pin = 0; + + master_spi[0].sck_pin = 0; + master_spi[0].copi_pin = 0; + master_spi[0].cipo_pin = 0; master_spi[0].cs_pin[0] = 0; master_spi[0].cs_pin[1] = 0; master_spi[0].cs_pin[2] = 0; @@ -108,13 +106,12 @@ cboard_STM32_H103::cboard_STM32_H103(void) { master_spi[1].cs_pin[1] = 0; master_spi[1].cs_pin[2] = 0; - // TODO read pin configuration from registers instead use fixed pins - master_uart[0].tx_pin = 42; // pa9 - master_uart[0].rx_pin = 43; // pa10 - master_uart[1].tx_pin = 16; // pa2 - master_uart[1].rx_pin = 17; // pa3 - master_uart[2].tx_pin = 29; // pb10 - master_uart[2].rx_pin = 30; // pb11 + master_uart[0].tx_pin = 0; + master_uart[0].rx_pin = 0; + master_uart[1].tx_pin = 0; + master_uart[1].rx_pin = 0; + master_uart[2].tx_pin = 0; + master_uart[2].rx_pin = 0; // label1 label1 = new CLabel(); @@ -715,7 +712,116 @@ void cboard_STM32_H103::MSetAPin(int pin, float value) { } } -void cboard_STM32_H103::PinsExtraConfig(int cfg) {} +void cboard_STM32_H103::PinsExtraConfig(int cfg) { + if ((cfg & 0x8008) == 0x8008) { // Alternate function + int pin = (cfg & 0x7FF0) >> 4; + int port = cfg & 0x0003; + uint32_t* uart_afio; + // int cfg_ = (cfg & 0x000C) >> 2; + // printf("Extra CFG port(%i) pin[%02i]=0x%02X \n", port, pin, cfg_); + + switch (port) { + case 0: // GPIOA + switch (pin) { + case 2: // uart2 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 15); + if (!(*uart_afio)) { + master_uart[1].ctrl_on = 1; + master_uart[1].tx_pin = 16; // pa2 + master_uart[1].rx_pin = 17; // pa3 + } + break; + case 5: + case 6: + case 7: // spi1 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 53); + if (!(*uart_afio)) { + master_spi[0].ctrl_on = 1; + master_spi[0].sck_pin = 21; // pa5 + master_spi[0].copi_pin = 23; // pa7 + master_spi[0].cipo_pin = 22; // pa6 + } + break; + case 9: // uart1 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 14); + if (!(*uart_afio)) { + master_uart[0].ctrl_on = 1; + master_uart[0].tx_pin = 42; // pa9 + master_uart[0].rx_pin = 43; // pa10 + } + break; + } + break; + case 1: // GPIOB + switch (pin) { + case 3: + case 4: + case 5: // spi1 (alt) + uart_afio = qemu_picsimlab_get_internals(0x1000 | 53); + if (!(*uart_afio)) { + master_spi[0].ctrl_on = 1; + master_spi[0].sck_pin = 55; // pb3 + master_spi[0].copi_pin = 57; // pb5 + master_spi[0].cipo_pin = 56; // pb4 + } + break; + case 6: // uart1 (alt) and i2c + uart_afio = qemu_picsimlab_get_internals(0x1000 | 14); + if ((*uart_afio)) { + master_uart[0].ctrl_on = 1; + master_uart[0].tx_pin = 58; // pb6 + master_uart[0].rx_pin = 59; // pb7 + } + // break; + case 7: // i2c0 + uart_afio = qemu_picsimlab_get_internals(0x1000 | 42); + if (!(*uart_afio)) { + master_i2c[0].ctrl_on = 1; + master_i2c[0].scl_pin = 58; // pb6 + master_i2c[0].sda_pin = 59; // pb7 + } + break; + case 8: + case 9: // i2c0 (alt) + uart_afio = qemu_picsimlab_get_internals(0x1000 | 42); + if ((*uart_afio)) { + master_i2c[0].ctrl_on = 1; + master_i2c[0].scl_pin = 61; // pb8 + master_i2c[0].sda_pin = 62; // pb9 + } + break; + case 10: // uart3 + /* + uart_afio = qemu_picsimlab_get_internals(0x1000 | 16); + if (!(*uart_afio)) { + master_uart[2].ctrl_on = 1; + master_uart[2].tx_pin = 29; // pb10 + master_uart[2].rx_pin = 30; // pb11 + } + */ + case 11: // i2c1 + master_i2c[1].ctrl_on = 1; + master_i2c[1].scl_pin = 29; // pb10 + master_i2c[1].sda_pin = 30; // pb11 + break; + + case 13: + case 14: + case 15: // spi2 + master_spi[1].ctrl_on = 1; + master_spi[1].sck_pin = 34; // pb13 + master_spi[1].copi_pin = 36; // pb15 + master_spi[1].cipo_pin = 35; // pb14 + break; + } + break; + case 2: // GPIOC + break; + case 3: // GPIOD + break; + } + } +} // Register the board in PICSimLab board_init(BOARD_STM32_H103_Name, cboard_STM32_H103); diff --git a/src/boards/bsim_qemu.cc b/src/boards/bsim_qemu.cc index 3860aba7..f8ecfa71 100644 --- a/src/boards/bsim_qemu.cc +++ b/src/boards/bsim_qemu.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2010-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2010-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -120,8 +120,6 @@ static int picsimlab_i2c_event(const uint8_t id, const uint8_t addr, const uint1 switch (event & 0xFF) { case I2C_START_RECV: case I2C_START_SEND: - // FIXME only for tests - g_board->master_i2c[id].ctrl_on = 1; // read from DPORT ? bitbang_i2c_ctrl_start(&g_board->master_i2c[id]); g_board->timer.last += 8000; @@ -166,8 +164,6 @@ static int picsimlab_i2c_event(const uint8_t id, const uint8_t addr, const uint1 static uint8_t picsimlab_spi_event(const uint8_t id, const uint16_t event) { g_board->Run_CPU_ns(GotoNow()); uint64_t cycle_ns = g_board->TimerGet_ns(g_board->master_spi[id].TimerID); - // FIXME only for tests - g_board->master_spi[id].ctrl_on = 1; // read from DPORT ? switch (event & 0xFF) { case 0: // tranfer @@ -201,9 +197,6 @@ static uint8_t picsimlab_spi_event(const uint8_t id, const uint16_t event) { static void picsimlab_uart_tx_event(const uint8_t id, const uint8_t value) { // printf("Uart[%i] %c \n", id, value); - // FIXME only for tests - g_board->master_uart[id].ctrl_on = 1; // read from DPORT ? - g_board->Run_CPU_ns(GotoNow()); bitbang_uart_send(&g_board->master_uart[id], value); diff --git a/src/boards/bsim_ucsim.cc b/src/boards/bsim_ucsim.cc index e16f70bd..0e4b128a 100644 --- a/src/boards/bsim_ucsim.cc +++ b/src/boards/bsim_ucsim.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2010-2020 Luis Claudio Gambôa Lopes + Copyright (c) : 2010-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -85,7 +85,7 @@ void bsim_ucsim::MSetSerial(const char* port) { } void bsim_ucsim::MEnd(void) { - ucsim_end(); // TODO + ucsim_end(); } int bsim_ucsim::MGetArchitecture(void) { diff --git a/src/devices/bitbang_i2c.cc b/src/devices/bitbang_i2c.cc index 89fb7db3..87717d28 100644 --- a/src/devices/bitbang_i2c.cc +++ b/src/devices/bitbang_i2c.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2020-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2020-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -52,6 +52,7 @@ void bitbang_i2c_rst(bitbang_i2c_t* i2c) { i2c->ret = 0; i2c->status = 0; i2c->data_reading = 0; + i2c->ctrl_on = 0; dprintf("bitbang_i2c %2x rst\n", i2c->addr >> 1); } @@ -257,7 +258,7 @@ static void bitbang_i2c_ctrl_callback(void* arg) { case 2: ioupdated = 1; i2c->scl_value = 1; - i2c->ack = i2c->sda_value; // FIXME + i2c->ack = i2c->sda_value; // FIXME verify ack break; case 3: i2c->scl_value = 1; @@ -304,7 +305,7 @@ static void bitbang_i2c_ctrl_callback(void* arg) { break; case 1: i2c->scl_value = 0; - i2c->sda_value = i2c->ack; // FIXME + i2c->sda_value = i2c->ack; // FIXME verify ack break; case 2: ioupdated = 1; @@ -329,7 +330,6 @@ void bitbang_i2c_ctrl_init(bitbang_i2c_t* i2c, board* pboard) { // only 100KHz speed i2c->TimerID = i2c->pboard->TimerRegister_us(2, bitbang_i2c_ctrl_callback, i2c); i2c->pboard->TimerSetState(i2c->TimerID, 0); - i2c->ctrl_on = 0; bitbang_i2c_rst(i2c); } @@ -344,7 +344,7 @@ void bitbang_i2c_ctrl_start(bitbang_i2c_t* i2c) { i2c->scl_value = 1; i2c->clkpc = 0; i2c->status = I2C_START; - i2c->pboard->TimerChange_us(i2c->TimerID, 2); // FIXME only 100kHzfrequency + i2c->pboard->TimerChange_us(i2c->TimerID, 2); // FIXME only 100kHz frequency i2c->pboard->TimerSetState(i2c->TimerID, 1); } diff --git a/src/devices/bitbang_i2c.h b/src/devices/bitbang_i2c.h index fe02420d..787b3106 100644 --- a/src/devices/bitbang_i2c.h +++ b/src/devices/bitbang_i2c.h @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2020-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2020-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/devices/bitbang_spi.cc b/src/devices/bitbang_spi.cc index 2edf2ed2..2cf1dd4d 100644 --- a/src/devices/bitbang_spi.cc +++ b/src/devices/bitbang_spi.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2020-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2020-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -42,6 +42,7 @@ void bitbang_spi_rst(bitbang_spi_t* spi) { spi->bit = 0; spi->byte = 0; spi->status = 0; + spi->ctrl_on = 0; dprintf("bitbang_spi rst\n"); } @@ -196,7 +197,6 @@ void bitbang_spi_ctrl_init(bitbang_spi_t* spi, board* pboard, const unsigned cha spi->pboard = pboard; spi->TimerID = spi->pboard->TimerRegister_us(2, bitbang_spi_ctrl_callback, spi); spi->pboard->TimerSetState(spi->TimerID, 0); - spi->ctrl_on = 0; spi->cs_value[0] = 1; spi->cs_value[1] = 1; spi->cs_value[2] = 1; diff --git a/src/devices/bitbang_spi.h b/src/devices/bitbang_spi.h index 47bb613e..25d08deb 100644 --- a/src/devices/bitbang_spi.h +++ b/src/devices/bitbang_spi.h @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2020-2022 Luis Claudio Gambôa Lopes + Copyright (c) : 2020-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/devices/bitbang_uart.cc b/src/devices/bitbang_uart.cc index 014e8219..445257c7 100644 --- a/src/devices/bitbang_uart.cc +++ b/src/devices/bitbang_uart.cc @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2020-2021 Luis Claudio Gambôa Lopes + Copyright (c) : 2020-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -45,6 +45,7 @@ void bitbang_uart_rst(bitbang_uart_t* bu) { bu->data_recv = 0; bu->data_to_send = 0; bu->tx_value = 1; + bu->ctrl_on = 0; dprintf("uart rst\n"); } diff --git a/src/devices/bitbang_uart.h b/src/devices/bitbang_uart.h index 09709ba9..c319177b 100644 --- a/src/devices/bitbang_uart.h +++ b/src/devices/bitbang_uart.h @@ -4,7 +4,7 @@ ######################################################################## - Copyright (c) : 2020-2021 Luis Claudio Gambôa Lopes + Copyright (c) : 2020-2023 Luis Claudio Gambôa Lopes This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by