1#include <avr/pgmspace.h>
16#define JOYSTICK_THRESHOLD 10
18#define IO_AVR_TOUCH_PAD 0x01
19#define IO_AVR_TOUCH_SLIDER 0x02
20#define IO_AVR_JOYSTICK 0x03
21#define IO_AVR_BUTTONS 0x04
22#define IO_AVR_LED_TOGGLE 0x05
23#define IO_AVR_LED_PWM 0x06
24#define IO_AVR_INFO 0x07
47 if (raw_x < dev->x_min)
49 if (raw_x > dev->
x_max)
51 if (raw_y < dev->y_min)
53 if (raw_y > dev->
y_max)
59 if (buffer->
x > -5 && buffer->
x < 5)
61 if (buffer->
y > -5 && buffer->
y < 5)
117 unsigned char recbuf[3];
122 btn->right = recbuf[0];
123 btn->left = recbuf[1];
124 btn->nav = recbuf[2];
129 unsigned char brightness) {
142 PORTB &= ~(1 << PB1);
170 DDRB |= (1 << PB4) | (1 << PB1) | (1 << PB2);
173 PORTB &= ~(1 << PB4);
216 for (uint8_t page = 0; page < 8; page++) {
219 for (uint8_t
x = 0;
x < 128;
x++) {
236 PORTB &= ~(1 << PB4);
277 if (line < 0 || line > 7)
281 for (uint8_t
x = 0;
x < 128;
x++) {
296 for (uint8_t line = 0; line < 8; line++) {
344 const struct oled_font *font,
char character_id) {
350 uint8_t glyph_id = 0;
353 if ((uint8_t)character_id >= 32 && (uint8_t)character_id <= 126) {
354 glyph_id = (uint8_t)character_id - 32;
363 uint8_t col = pgm_read_byte(base + c);
368 for (uint8_t s = 0; s < font->
spacing; ++s) {
378 const struct oled_font *font,
char *text) {
379 if (!dev || !font || !text)
382 for (
char *p = text; *p; ++p) {
396 for (uint8_t i = 0; i < 64; i++) {
403 for (uint8_t i = 0; i < 64; i++) {
411 for (uint8_t i = 0; i < 128; i++) {
423 for (uint8_t i = 0; i < 128; i++) {
454 for (uint8_t blink = 0; blink < 2 * blinks; blink++) {
455 for (uint8_t row = 0; row < 8; row++) {
458 for (uint8_t col = 0; col < 128; col++) {
459 if (blink % 2 == 0) {
ADC memory-mapped interface.
void ADC_init(void)
Initialize the external memory–mapped ADC interface.
void ADC_read_all(struct ADC_meas *output)
Perform a full four-channel ADC conversion and return all results.
int io_avr_led_set(struct io_avr_device *dev, unsigned char led, unsigned char brightness)
io_joystick_direction
Predefined joystick directions.
int io_avr_init(struct io_avr_device *dev)
int io_joystick_read_position(struct io_joystick_device *dev, struct io_joystick_position *buffer)
Read the position of a joystick as a percentage from 0 in each axis.
int io_oled_clear_all(struct io_oled_device *dev)
Clears all lines on the OLED (fills entire display with black).
int io_avr_buttons_read(struct io_avr_device *dev, struct io_avr_buttons *btn)
static const struct oled_font OLED_FONT_4x6
Predefined 4x6 font for OLED.
static const struct oled_font OLED_FONT_8x8
Predefined 8x8 font for OLED.
int io_oled_goto_line(struct io_oled_device *dev, int line)
Go to specific line in OLED.
int io_oled_write_command(struct io_oled_device *dev, uint8_t command)
int io_oled_print_arrow(struct io_oled_device *dev, uint8_t row, uint8_t col)
Prints an arrow at a specified postion.
int io_oled_clear_line(struct io_oled_device *dev, int line)
Clear specific line in OLED.
int io_oled_home(struct io_oled_device *dev)
Loads homescreen to OLED.
int io_oled_blink(struct io_oled_device *dev, uint8_t blinks)
Alternates screen between black and white.
int io_oled_write_data(struct io_oled_device *dev, uint8_t data)
int io_oled_reset(struct io_oled_device *dev)
Sends command to OLED.
int io_oled_reset_brightness(struct io_oled_device *dev)
Reset OLED brightness.
static const struct oled_font OLED_FONT_5x7
Predefined 5x7 font for OLED.
uint8_t io_oled_write_glyph(struct io_oled_device *dev, const struct oled_font *font, char character_id)
Prints a single glyph in a specifiec font.
int io_oled_pos(struct io_oled_device *dev, int line, int column)
Set specific position in OLED.
int io_joystick_read_direction(struct io_joystick_device *dev, enum io_joystick_direction *direction)
Fetches the direction of a joystick.
int io_oled_set_brightness(struct io_oled_device *dev, uint8_t brightness)
Set OLED brightness.
int io_joystick_init(struct io_joystick_device *dev)
Initialise and calibrate a joystick.
int io_oled_goto_column(struct io_oled_device *dev, int column)
Go to specific column in OLED.
int io_oled_print_with_font(struct io_oled_device *dev, const struct oled_font *font, char *text)
Prints an arrow at a specified postion.
int io_oled_test(struct io_oled_device *dev)
Prints a known image to the OLED to confirm that it can print and navigate the screen.
int io_oled_init(struct io_oled_device *dev)
Initialise OLED.
#define LOG_MODULE_DEFINE(name)
int spi_recieve_n(enum spi_slave *slave, unsigned char *out, int length)
Receive several bytes from a slave.
int spi_send_n(enum spi_slave *slave, unsigned char *data, int length)
Send a sequence of bytes to a slave without reading response.
int spi_ready(void)
Check if the SPI subsystem is initialized.
int spi_set_slave_select(enum spi_slave *slave, unsigned char state)
Set the slave-select line for the given device.
int spi_push(enum spi_slave *slave, unsigned char data, unsigned char *out)
Push one byte to a slave and optionally read the response.
int spi_send(enum spi_slave *slave, unsigned char data)
Send a single byte to a slave.
int spi_init(void)
Initialize SPI in master mode.
int16_t map(uint8_t x, uint8_t in_min, uint8_t in_max, int16_t out_min, int16_t out_max)
Maps a value from one range to another (taken from https://docs.arduino.cc/language-reference/en/func...
#define JOYSTICK_THRESHOLD
static int _io_oled_write(struct io_oled_device *dev, uint8_t data)
static int _io_oled_cmd(struct io_oled_device *dev, uint8_t command)
Driver for joystick, buttons, and OLED.
Logging interface for debug messages.
struct io_avr_buttons btn
struct io_joystick_position pos
Container for ADC measurement results.
Represents an SPI-connected AVR-I/O board.
Represents a joystick input device.
unsigned int adc_channel_x
unsigned int adc_channel_y
Represents the position of a joystick relative to center.
Represents an OLED display device controlled via SPI.
Represents a font for OLED displays.
UART communication driver.
Utility and helper functions for joystick, LED debugging, and mapping.