diff options
| author | dmlunar <root@lunar.sh> | 2025-01-22 16:47:21 +0200 |
|---|---|---|
| committer | dmlunar <root@lunar.sh> | 2025-10-15 23:42:50 +0200 |
| commit | 729f2a2c3ebfb2612d873caf453a1d7ca02180d9 (patch) | |
| tree | 7bab2fcc0c7f50eab3013348697bc06ddd71d551 /firmware/inc/peripheral | |
| download | varpa-729f2a2c3ebfb2612d873caf453a1d7ca02180d9.tar.gz varpa-729f2a2c3ebfb2612d873caf453a1d7ca02180d9.zip | |
varpa: initial public commit
Diffstat (limited to 'firmware/inc/peripheral')
| -rw-r--r-- | firmware/inc/peripheral/ring.h | 77 | ||||
| -rw-r--r-- | firmware/inc/peripheral/spi.h | 34 | ||||
| -rw-r--r-- | firmware/inc/peripheral/timer.h | 22 | ||||
| -rw-r--r-- | firmware/inc/peripheral/twi.h | 35 | ||||
| -rw-r--r-- | firmware/inc/peripheral/uart.h | 56 |
5 files changed, 224 insertions, 0 deletions
diff --git a/firmware/inc/peripheral/ring.h b/firmware/inc/peripheral/ring.h new file mode 100644 index 0000000..d2a713d --- /dev/null +++ b/firmware/inc/peripheral/ring.h @@ -0,0 +1,77 @@ +/** + * + * Author: Dylan Muller + * Copyright (c) 2025 + * All rights reserved. + * + * - Commercial/IP use prohibited. + * - Attribution required. + * See License.txt + * + */ + +#ifndef RING_H_ +#define RING_H_ + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +typedef struct +{ + uint8_t *buf; + uint8_t *end; + uint8_t *write; + uint8_t *read; +} ring_t; + +#define RING_INIT(buf_, len_) \ + ((ring_t){ \ + .buf = (buf_), \ + .end = (buf_)+(len_), \ + .write = (buf_), \ + .read = (buf_)} \ + ) + +ring_t ring_init( + uint8_t *buf, + size_t len +); + +bool ring_is_empty( + ring_t ring +); + +bool ring_is_full( + ring_t ring +); + +size_t ring_push_available( + ring_t ring +); + +size_t ring_pop_available( + ring_t ring +); + +bool ring_push( + ring_t *ring, + uint8_t data +); + +bool ring_push_over( + ring_t *ring, + uint8_t data +); + +bool ring_pop( + ring_t *ring, + uint8_t *data +); + +bool ring_peek( + ring_t *ring, + uint8_t *data +); + +#endif diff --git a/firmware/inc/peripheral/spi.h b/firmware/inc/peripheral/spi.h new file mode 100644 index 0000000..003fc04 --- /dev/null +++ b/firmware/inc/peripheral/spi.h @@ -0,0 +1,34 @@ +/** + * + * Author: Dylan Muller + * Copyright (c) 2025 + * All rights reserved. + * + * - Commercial/IP use prohibited. + * - Attribution required. + * See License.txt + * + */ + +#ifndef SPI_H_ +#define SPI_H_ + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +void spi_init(void); + +bool spi_busy(void); + +void spi_flush(void); + +void spi_start( + uint8_t *out, + uint8_t *in, + size_t len, + uint8_t *port, + uint8_t pin +); + +#endif diff --git a/firmware/inc/peripheral/timer.h b/firmware/inc/peripheral/timer.h new file mode 100644 index 0000000..ff45c85 --- /dev/null +++ b/firmware/inc/peripheral/timer.h @@ -0,0 +1,22 @@ +/** + * + * Author: Dylan Muller + * Copyright (c) 2025 + * All rights reserved. + * + * - Commercial/IP use prohibited. + * - Attribution required. + * See License.txt + * + */ + +#ifndef TIMER_H_ +#define TIMER_H_ + +#include <stdint.h> + +void timer_init(void); +void timer_reset(void); +uint32_t timer_millis(void); + +#endif diff --git a/firmware/inc/peripheral/twi.h b/firmware/inc/peripheral/twi.h new file mode 100644 index 0000000..8f08777 --- /dev/null +++ b/firmware/inc/peripheral/twi.h @@ -0,0 +1,35 @@ +/** + * + * Author: Dylan Muller + * Copyright (c) 2025 + * All rights reserved. + * + * - Commercial/IP use prohibited. + * - Attribution required. + * See License.txt + * + */ + +#ifndef TWI_H_ +#define TWI_H_ + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#define TWI_ADDRESS_W(x) (((x) << 1) & ~0x01) +#define TWI_ADDRESS_R(x) (((x) << 1) | 0x01) + +void twi_init(void); + +bool twi_busy(void); + +void twi_flush(void); + +void twi_start( + uint8_t address, + uint8_t *data, + size_t len +); + +#endif diff --git a/firmware/inc/peripheral/uart.h b/firmware/inc/peripheral/uart.h new file mode 100644 index 0000000..e2a0f3d --- /dev/null +++ b/firmware/inc/peripheral/uart.h @@ -0,0 +1,56 @@ +/** + * + * Author: Dylan Muller + * Copyright (c) 2025 + * All rights reserved. + * + * - Commercial/IP use prohibited. + * - Attribution required. + * See License.txt + * + */ + +#ifndef UARTINT_H_ +#define UARTINT_H_ + +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> +#include <stdbool.h> + +extern FILE uart_out; +extern FILE uart_in; + +void uart_init(void); + +bool uart_tx( + uint8_t data +); + +bool uart_rx( + uint8_t* data +); + +size_t uart_tx_burst( + uint8_t* data, + size_t size +); + +size_t uart_rx_burst( + uint8_t* data, + size_t size +); + +size_t uart_tx_available(void); + +size_t uart_rx_available(void); + +bool uart_rx_peek( + uint8_t* data +); + +void uart_tx_flush(void); + +char *uart_ngets(char *s, size_t n); + +#endif |
