mirror of
https://github.com/mytechnotalent/Embedded-Hacking.git
synced 2026-07-06 12:37:54 +02:00
Updated Drivers
This commit is contained in:
@@ -46,32 +46,23 @@
|
||||
#define UART_RX_PIN 1
|
||||
#define UART_BAUD 115200
|
||||
|
||||
/**
|
||||
* @brief Convert a lowercase ASCII character to uppercase
|
||||
*
|
||||
* Returns the uppercase equivalent if the character is in 'a'-'z';
|
||||
* all other characters are passed through unchanged.
|
||||
*
|
||||
* @param c Input character
|
||||
* @return char Uppercase equivalent, or the original character
|
||||
*/
|
||||
static char to_upper(char c) {
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
return (char)(c - 32);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Application entry point for the UART uppercase echo demo
|
||||
*
|
||||
* Initializes UART0 and enters an infinite loop that reads incoming
|
||||
* characters, converts them to uppercase, and echoes them back.
|
||||
*
|
||||
* @return int Does not return
|
||||
*/
|
||||
int main(void) {
|
||||
uart_driver_init(UART_TX_PIN, UART_RX_PIN, UART_BAUD);
|
||||
|
||||
uart_driver_puts("UART driver ready (115200 8N1)\r\n");
|
||||
uart_driver_puts("Type characters to echo them back in UPPERCASE:\r\n");
|
||||
|
||||
while (true) {
|
||||
if (uart_driver_is_readable()) {
|
||||
char c = uart_driver_getchar();
|
||||
char upper = to_upper(c);
|
||||
char upper = uart_driver_to_upper(c);
|
||||
uart_driver_putchar(upper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,26 +34,39 @@
|
||||
|
||||
#define UART_INST uart0
|
||||
|
||||
|
||||
void uart_driver_init(uint32_t tx_pin, uint32_t rx_pin, uint32_t baud_rate) {
|
||||
uart_init(UART_INST, baud_rate);
|
||||
gpio_set_function(tx_pin, GPIO_FUNC_UART);
|
||||
gpio_set_function(rx_pin, GPIO_FUNC_UART);
|
||||
}
|
||||
|
||||
|
||||
bool uart_driver_is_readable(void) {
|
||||
return uart_is_readable(UART_INST);
|
||||
}
|
||||
|
||||
|
||||
char uart_driver_getchar(void) {
|
||||
return (char)uart_getc(UART_INST);
|
||||
}
|
||||
|
||||
|
||||
void uart_driver_putchar(char c) {
|
||||
uart_putc_raw(UART_INST, c);
|
||||
}
|
||||
|
||||
|
||||
void uart_driver_puts(const char *str) {
|
||||
while (*str) {
|
||||
uart_putc_raw(UART_INST, *str++);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char uart_driver_to_upper(char c) {
|
||||
if (c >= 'a' && c <= 'z') {
|
||||
return (char)(c - 32);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
@@ -86,4 +86,15 @@ void uart_driver_putchar(char c);
|
||||
*/
|
||||
void uart_driver_puts(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Convert a lowercase ASCII character to uppercase
|
||||
*
|
||||
* Returns the uppercase equivalent if the character is in 'a'-'z';
|
||||
* all other characters are passed through unchanged.
|
||||
*
|
||||
* @param c Input character
|
||||
* @return char Uppercase equivalent, or the original character
|
||||
*/
|
||||
char uart_driver_to_upper(char c);
|
||||
|
||||
#endif // UART_H
|
||||
|
||||
Reference in New Issue
Block a user