TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
io.h
Go to the documentation of this file.
1
8
9#ifndef INCLUDE_INCLUDE_IO_H_
10#define INCLUDE_INCLUDE_IO_H_
11
12#include "fonts.h"
13#include "spi.h"
14#include <stdint.h>
15
22struct oled_font {
23 const void *table;
25 uint8_t height;
26 uint8_t spacing;
27};
28
30static const struct oled_font OLED_FONT_8x8 = {font8, 8, 8, 1};
32static const struct oled_font OLED_FONT_5x7 = {font5, 5, 7, 1};
34static const struct oled_font OLED_FONT_4x6 = {font4, 4, 6, 1};
35
41};
42
48 uint8_t current_page;
50};
51
56 unsigned int adc_channel_x;
57 unsigned int adc_channel_y;
58
59 // Calibration
60 int x_min;
61 int y_min;
62 int x_max;
63 int y_max;
64};
65
71 int8_t x;
72 int8_t y;
73};
74
85
91struct __attribute__((packed)) io_avr_buttons {
92 union {
93 uint8_t right;
94 struct {
95 uint8_t R1 : 1;
96 uint8_t R2 : 1;
97 uint8_t R3 : 1;
98 uint8_t R4 : 1;
99 uint8_t R5 : 1;
100 uint8_t R6 : 1;
101 };
102 };
103 union {
104 uint8_t left;
105 struct {
106 uint8_t L1 : 1;
107 uint8_t L2 : 1;
108 uint8_t L3 : 1;
109 uint8_t L4 : 1;
110 uint8_t L5 : 1;
111 uint8_t L6 : 1;
112 uint8_t L7 : 1;
113 };
114 };
115 union {
116 uint8_t nav;
117 struct {
118 uint8_t NB : 1;
119 uint8_t NR : 1;
120 uint8_t ND : 1;
121 uint8_t NL : 1;
122 uint8_t NU : 1;
123 };
124 };
125};
126
127//------------------//
128// Joystick //
129//------------------//
130
136int io_joystick_init(struct io_joystick_device *dev);
137
145 struct io_joystick_position *buffer);
146
154 enum io_joystick_direction *direction);
155
163
164//-------------------//
165// Button Inputs //
166//-------------------//
167
168int io_avr_init(struct io_avr_device *dev);
169int io_avr_buttons_read(struct io_avr_device *dev, struct io_avr_buttons *btn);
170int io_avr_led_set(struct io_avr_device *dev, unsigned char led,
171 unsigned char brightness);
172
173//------------------//
174// OLED //
175//------------------//
176
182int io_oled_init(struct io_oled_device *dev);
183
190// int io_oled_cmd(struct io_oled_device *dev, uint8_t command);
191
198// int io_oled_write(struct io_oled_device *dev, uint8_t data);
199
205int io_oled_reset(struct io_oled_device *dev);
206
212int io_oled_home(struct io_oled_device *dev);
213
220int io_oled_goto_line(struct io_oled_device *dev, int line);
221
228int io_oled_goto_column(struct io_oled_device *dev, int column);
229
236int io_oled_clear_line(struct io_oled_device *dev, int line);
237
244volatile int io_oled_writedata(struct io_oled_device *dev, int data);
245
253int io_oled_pos(struct io_oled_device *dev, int row, int column);
254
261int io_oled_print(struct io_oled_device *dev, char *text);
262
269int io_oled_set_brightness(struct io_oled_device *dev, uint8_t brightness);
270
277
285int io_oled_print_arrow(struct io_oled_device *dev, uint8_t row, uint8_t col);
286
294uint8_t io_oled_write_glyph(struct io_oled_device *dev,
295 const struct oled_font *font, char character_id);
296
306 const struct oled_font *font, char *text);
307
315int io_oled_test(struct io_oled_device *dev);
316
324int io_oled_blink(struct io_oled_device *dev, uint8_t blinks);
325
326int io_oled_write_data(struct io_oled_device *dev, uint8_t data);
327int io_oled_write_command(struct io_oled_device *dev, uint8_t command);
328
329// NEW FOR TESTING
330int io_oled_clear_all(struct io_oled_device *dev);
331
332#endif // INCLUDE_INCLUDE_IO_H_
333
const unsigned char PROGMEM font5[95][5]
Definition fonts.c:104
const unsigned char PROGMEM font4[95][4]
Definition fonts.c:203
const unsigned char PROGMEM font8[95][8]
Definition fonts.c:5
int io_avr_led_set(struct io_avr_device *dev, unsigned char led, unsigned char brightness)
Definition io.c:128
struct __attribute__((packed)) io_avr_buttons
Represents button states for I/O boards (from I/O board manual).
Definition io.h:91
io_joystick_direction
Predefined joystick directions.
Definition io.h:78
volatile int io_oled_writedata(struct io_oled_device *dev, int data)
Writes data to OLED at current position.
int io_avr_init(struct io_avr_device *dev)
Definition io.c:106
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.
Definition io.c:38
int io_joystick_calibrate(struct io_joystick_device *dev)
Calibrate a joystick. Requires the joystick to be in its neutral position.
int io_oled_clear_all(struct io_oled_device *dev)
Clears all lines on the OLED (fills entire display with black).
Definition io.c:292
int io_avr_buttons_read(struct io_avr_device *dev, struct io_avr_buttons *btn)
Definition io.c:115
static const struct oled_font OLED_FONT_4x6
Predefined 4x6 font for OLED.
Definition io.h:34
static const struct oled_font OLED_FONT_8x8
Predefined 8x8 font for OLED.
Definition io.h:30
int io_oled_goto_line(struct io_oled_device *dev, int line)
Go to specific line in OLED.
Definition io.c:255
int io_oled_write_command(struct io_oled_device *dev, uint8_t command)
Definition io.c:475
int io_oled_print_arrow(struct io_oled_device *dev, uint8_t row, uint8_t col)
Prints an arrow at a specified postion.
Definition io.c:330
int io_oled_clear_line(struct io_oled_device *dev, int line)
Clear specific line in OLED.
Definition io.c:275
int io_oled_home(struct io_oled_device *dev)
Loads homescreen to OLED.
Definition io.c:247
int io_oled_blink(struct io_oled_device *dev, uint8_t blinks)
Alternates screen between black and white.
Definition io.c:450
int io_oled_write_data(struct io_oled_device *dev, uint8_t data)
Definition io.c:471
int io_oled_reset(struct io_oled_device *dev)
Sends command to OLED.
Definition io.c:230
int io_oled_reset_brightness(struct io_oled_device *dev)
Reset OLED brightness.
Definition io.c:322
static const struct oled_font OLED_FONT_5x7
Predefined 5x7 font for OLED.
Definition io.h:32
int io_oled_print(struct io_oled_device *dev, char *text)
Write string to 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.
Definition io.c:343
int io_oled_pos(struct io_oled_device *dev, int row, int column)
Set specific position in OLED.
Definition io.c:306
int io_joystick_read_direction(struct io_joystick_device *dev, enum io_joystick_direction *direction)
Fetches the direction of a joystick.
Definition io.c:66
int io_oled_set_brightness(struct io_oled_device *dev, uint8_t brightness)
Set OLED brightness.
Definition io.c:314
int io_joystick_init(struct io_joystick_device *dev)
Initialise and calibrate a joystick.
Definition io.c:30
int io_oled_goto_column(struct io_oled_device *dev, int column)
Go to specific column in OLED.
Definition io.c:265
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.
Definition io.c:377
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.
Definition io.c:391
int io_oled_init(struct io_oled_device *dev)
Initialise OLED.
Definition io.c:161
@ DOWN
Definition io.h:82
@ UP
Definition io.h:81
@ LEFT
Definition io.h:79
@ RIGHT
Definition io.h:80
@ NEUTRAL
Definition io.h:83
spi_slave
Identifiers for available SPI slave devices.
Definition spi.h:15
struct io_avr_buttons btn
Definition main.c:59
SPI driver.
Represents an SPI-connected AVR-I/O board.
Definition io.h:39
enum spi_slave spi
Definition io.h:40
Represents a joystick input device.
Definition io.h:55
unsigned int adc_channel_x
Definition io.h:56
unsigned int adc_channel_y
Definition io.h:57
Represents the position of a joystick relative to center.
Definition io.h:70
Represents an OLED display device controlled via SPI.
Definition io.h:46
enum spi_slave spi
Definition io.h:47
uint8_t current_page
Definition io.h:48
uint8_t current_column
Definition io.h:49
Represents a font for OLED displays.
Definition io.h:22
uint8_t spacing
Definition io.h:26
const void * table
Definition io.h:23
uint8_t bytes_per_glyph
Definition io.h:24
uint8_t height
Definition io.h:25