Skip to content

Commit

Permalink
Added untested shutdown logic
Browse files Browse the repository at this point in the history
  • Loading branch information
o7-machinehum committed Apr 29, 2024
1 parent e05950c commit 52e8e75
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stm32-app/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int main(void)
uart1_out(buf);
}

if(!gpio_get(GPIOA, GPIO0)) {
if(!gpio_get(GPIOA, GPIO0) || uart_get_shutdown()) {
sprintf(buf, "Shutting down\n\r");
uart1_out(buf);
bq76920_shutdown();
Expand Down
20 changes: 20 additions & 0 deletions stm32-app/uart.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "uart.h"

static bool shutdown = false;

void uart1_out(char *data)
{
while (*data) {
Expand All @@ -25,8 +27,24 @@ void usart1_setup(int baud)
usart_enable(USART1);
}

bool uart_get_shutdown(void) {
return shutdown;
}

void usart2_isr(void)
{
static uint8_t data = 'A';
data = usart_recv(USART2);

if(data == 0x00) {
shutdown = true;
}
}

void usart2_setup(int baud)
{
nvic_enable_irq(NVIC_USART2_LPUART2_IRQ);

gpio_mode_setup(GPIOA, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO3);
gpio_set_af(GPIOA, GPIO_AF1, GPIO3);

Expand All @@ -38,6 +56,8 @@ void usart2_setup(int baud)
usart_set_mode(USART2, USART_MODE_RX);
usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);

usart_enable_rx_interrupt(USART2);

/* Finally enable the USART. */
usart_enable(USART2);
}
3 changes: 3 additions & 0 deletions stm32-app/uart.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <libopencm3/stm32/usart.h>
#include <libopencm3/stm32/syscfg.h>
#include <libopencm3/stm32/gpio.h>
#include <libopencm3/stm32/g0/nvic.h>

void usart1_setup(int baud);
void uart1_out(char *data);
void usart2_setup(int baud);
void usart2_isr(void);
bool uart_get_shutdown(void);

0 comments on commit 52e8e75

Please sign in to comment.