Skip to content

Commit

Permalink
chg: Add support to set baud rate in bitbang_uart (ESP32 and ESP32C3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Jun 30, 2024
1 parent 34d91b3 commit fa5cc20
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.2
DATE=240629
DATE=240630
VERSION_STABLE=0.9.1
Binary file modified share/boards/ESP32-C3-DevKitC-02/demo.pzw
Binary file not shown.
Binary file modified share/boards/ESP32-DevKitC/demo.pzw
Binary file not shown.
9 changes: 7 additions & 2 deletions src/boards/board_C3_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ void cboard_C3_DevKitC::Reset(void) {

MReset(1);

PICSimLab.UpdateStatus(PS_SERIAL, "Serial: " + std::string(SERIALDEVICE));
uint32_t baud_rate = *qemu_picsimlab_get_internals(QEMU_INTERNAL_UART0_BAUD);
bitbang_uart_set_speed(&master_uart[0], baud_rate);
PICSimLab.UpdateStatus(PS_SERIAL, "Serial: " + std::string(SERIALDEVICE) + "(" + std::to_string(baud_rate) + ")");

if (use_spare)
SpareParts.Reset();
Expand All @@ -307,7 +309,10 @@ void cboard_C3_DevKitC::RegisterRemoteControl(void) {

void cboard_C3_DevKitC::RefreshStatus(void) {
if (serial_open) {
PICSimLab.UpdateStatus(PS_SERIAL, "Serial: " + std::string(SERIALDEVICE));
uint32_t baud_rate = *qemu_picsimlab_get_internals(QEMU_INTERNAL_UART0_BAUD);
bitbang_uart_set_speed(&master_uart[0], baud_rate);
PICSimLab.UpdateStatus(PS_SERIAL,
"Serial: " + std::string(SERIALDEVICE) + "(" + std::to_string(baud_rate) + ")");
} else {
PICSimLab.UpdateStatus(PS_SERIAL, "Serial: Error");
}
Expand Down
9 changes: 7 additions & 2 deletions src/boards/board_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ void cboard_DevKitC::Reset(void) {

MReset(1);

PICSimLab.UpdateStatus(PS_SERIAL, "Serial: " + std::string(SERIALDEVICE));
uint32_t baud_rate = *qemu_picsimlab_get_internals(QEMU_INTERNAL_UART0_BAUD);
bitbang_uart_set_speed(&master_uart[0], baud_rate);
PICSimLab.UpdateStatus(PS_SERIAL, "Serial: " + std::string(SERIALDEVICE) + "(" + std::to_string(baud_rate) + ")");

if (use_spare)
SpareParts.Reset();
Expand All @@ -368,7 +370,10 @@ void cboard_DevKitC::RegisterRemoteControl(void) {

void cboard_DevKitC::RefreshStatus(void) {
if (serial_open) {
PICSimLab.UpdateStatus(PS_SERIAL, "Serial: " + std::string(SERIALDEVICE));
uint32_t baud_rate = *qemu_picsimlab_get_internals(QEMU_INTERNAL_UART0_BAUD);
bitbang_uart_set_speed(&master_uart[0], baud_rate);
PICSimLab.UpdateStatus(PS_SERIAL,
"Serial: " + std::string(SERIALDEVICE) + "(" + std::to_string(baud_rate) + ")");
} else {
PICSimLab.UpdateStatus(PS_SERIAL, "Serial: Error");
}
Expand Down
12 changes: 10 additions & 2 deletions src/boards/bsim_qemu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,16 @@ 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) {
dprintf("Uart[%i] %c \n", id, value);

uint32_t baud_rate = *qemu_picsimlab_get_internals(QEMU_INTERNAL_UART0_BAUD + id);
bitbang_uart_set_speed(&g_board->master_uart[id], baud_rate);

unsigned long delta = (1e10 / baud_rate);

g_board->Run_CPU_ns(GotoNow());

bitbang_uart_send(&g_board->master_uart[id], value);
g_board->timer.last += 1041667;
g_board->Run_CPU_ns(1041667); // TODO fixed 10 bits at 9600 bps
g_board->timer.last += delta;
g_board->Run_CPU_ns(delta);
}

static void picsimlab_uart_rx_event(bitbang_uart_t* bu, void* arg) {
Expand Down Expand Up @@ -334,6 +339,9 @@ bsim_qemu::bsim_qemu(void) {
bitbang_uart_init(&master_uart[0], this, picsimlab_uart_rx_event, (void*)&id[0]);
bitbang_uart_init(&master_uart[1], this, picsimlab_uart_rx_event, (void*)&id[1]);
bitbang_uart_init(&master_uart[2], this, picsimlab_uart_rx_event, (void*)&id[2]);
bitbang_uart_set_speed(&master_uart[0], 115200);
bitbang_uart_set_speed(&master_uart[1], 115200);
bitbang_uart_set_speed(&master_uart[2], 115200);
}

bsim_qemu::~bsim_qemu(void) {
Expand Down

0 comments on commit fa5cc20

Please sign in to comment.