TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
IO Devices

Data Structures

struct  oled_font
 Represents a font for OLED displays. More...
struct  io_avr_device
 Represents an SPI-connected AVR-I/O board. More...
struct  io_oled_device
 Represents an OLED display device controlled via SPI. More...
struct  io_joystick_device
 Represents a joystick input device. More...
struct  io_joystick_position
 Represents the position of a joystick relative to center. More...

Enumerations

enum  io_joystick_direction {
  LEFT , RIGHT , UP , DOWN ,
  NEUTRAL
}
 Predefined joystick directions. More...

Functions

struct __attribute__ ((packed)) io_avr_buttons
 Represents button states for I/O boards (from I/O board manual).
int io_joystick_init (struct io_joystick_device *dev)
 Initialise and calibrate a joystick.
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_joystick_read_direction (struct io_joystick_device *dev, enum io_joystick_direction *direction)
 Fetches the direction of a joystick.
int io_joystick_calibrate (struct io_joystick_device *dev)
 Calibrate a joystick. Requires the joystick to be in its neutral position.
int io_avr_init (struct io_avr_device *dev)
int io_avr_buttons_read (struct io_avr_device *dev, struct io_avr_buttons *btn)
int io_avr_led_set (struct io_avr_device *dev, unsigned char led, unsigned char brightness)
int io_oled_init (struct io_oled_device *dev)
 Initialise OLED.
int io_oled_reset (struct io_oled_device *dev)
 Sends command to OLED.
int io_oled_home (struct io_oled_device *dev)
 Loads homescreen to OLED.
int io_oled_goto_line (struct io_oled_device *dev, int line)
 Go to specific line in OLED.
int io_oled_goto_column (struct io_oled_device *dev, int column)
 Go to specific column in OLED.
int io_oled_clear_line (struct io_oled_device *dev, int line)
 Clear specific line in OLED.
volatile int io_oled_writedata (struct io_oled_device *dev, int data)
 Writes data to OLED at current position.
int io_oled_pos (struct io_oled_device *dev, int row, int column)
 Set specific position in OLED.
int io_oled_print (struct io_oled_device *dev, char *text)
 Write string to OLED.
int io_oled_set_brightness (struct io_oled_device *dev, uint8_t brightness)
 Set OLED brightness.
int io_oled_reset_brightness (struct io_oled_device *dev)
 Reset OLED brightness.
int io_oled_print_arrow (struct io_oled_device *dev, uint8_t row, uint8_t col)
 Prints an arrow at a specified postion.
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_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_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_write_command (struct io_oled_device *dev, uint8_t command)
int io_oled_clear_all (struct io_oled_device *dev)
 Clears all lines on the OLED (fills entire display with black).

Variables

static const struct oled_font OLED_FONT_8x8 = {font8, 8, 8, 1}
 Predefined 8x8 font for OLED.
static const struct oled_font OLED_FONT_5x7 = {font5, 5, 7, 1}
 Predefined 5x7 font for OLED.
static const struct oled_font OLED_FONT_4x6 = {font4, 4, 6, 1}
 Predefined 4x6 font for OLED.

Detailed Description

Enumeration Type Documentation

◆ io_joystick_direction

#include <io.h>

Predefined joystick directions.

Enumerator
LEFT 

Joystick pushed left

RIGHT 

Joystick pushed right

UP 

Joystick pushed up

DOWN 

Joystick pushed down

NEUTRAL 

Joystick in neutral position

Definition at line 78 of file io.h.

78 {
79 LEFT,
80 RIGHT,
81 UP,
82 DOWN,
83 NEUTRAL
84};
@ 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

Function Documentation

◆ __attribute__()

struct __attribute__ ( (packed) )

#include <io.h>

Represents button states for I/O boards (from I/O board manual).

Buttons are packed as bits inside unions for convenient access.

< All right-side buttons as byte

< All left-side buttons as byte

< Navigation buttons as byte

< Bottom navigation button

< Right navigation button

< Down navigation button

< Left navigation button

< Up navigation button

Definition at line 34 of file io.h.

91 {
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};

◆ io_avr_buttons_read()

int io_avr_buttons_read ( struct io_avr_device * dev,
struct io_avr_buttons * btn )

#include <io.h>

Definition at line 115 of file io.c.

115 {
116
117 unsigned char recbuf[3];
119 spi_recieve_n(&dev->spi, recbuf, 3);
120 spi_set_slave_select(&dev->spi, 1);
121
122 btn->right = recbuf[0];
123 btn->left = recbuf[1];
124 btn->nav = recbuf[2];
125
126 return 0;
127}
int spi_recieve_n(enum spi_slave *slave, unsigned char *out, int length)
Receive several bytes from a slave.
Definition spi.c:96
int spi_set_slave_select(enum spi_slave *slave, unsigned char state)
Set the slave-select line for the given device.
Definition spi.c:43
int spi_push(enum spi_slave *slave, unsigned char data, unsigned char *out)
Push one byte to a slave and optionally read the response.
Definition spi.c:154
#define TRASHCAN
Definition utils.h:19
#define IO_AVR_BUTTONS
Definition io.c:21
struct io_avr_buttons btn
Definition main.c:59
enum spi_slave spi
Definition io.h:40

Referenced by main(), and tx_joy_btn().

◆ io_avr_init()

int io_avr_init ( struct io_avr_device * dev)

#include <io.h>

Definition at line 106 of file io.c.

106 {
107
108 int status = 0;
109
110 while (spi_ready()) {
111 status = spi_init();
112 }
113 return status;
114}
int spi_ready(void)
Check if the SPI subsystem is initialized.
Definition spi.c:41
int spi_init(void)
Initialize SPI in master mode.
Definition spi.c:9

Referenced by main().

◆ io_avr_led_set()

int io_avr_led_set ( struct io_avr_device * dev,
unsigned char led,
unsigned char brightness )

#include <io.h>

Definition at line 128 of file io.c.

129 {
130 unsigned char cmd[3] = {IO_AVR_LED_PWM, led, brightness};
131 spi_send_n(&dev->spi, cmd, 3);
132 return 0;
133}
int spi_send_n(enum spi_slave *slave, unsigned char *data, int length)
Send a sequence of bytes to a slave without reading response.
Definition spi.c:81
#define IO_AVR_LED_PWM
Definition io.c:23

◆ io_joystick_calibrate()

int io_joystick_calibrate ( struct io_joystick_device * dev)

#include <io.h>

Calibrate a joystick. Requires the joystick to be in its neutral position.

Parameters
[in]devThe joystick to calibrate.
Returns
Errno.

◆ io_joystick_init()

int io_joystick_init ( struct io_joystick_device * dev)

#include <io.h>

Initialise and calibrate a joystick.

Parameters
[in]devThe joystick to be initlaised.
Returns
Errno.

Definition at line 30 of file io.c.

30 {
31 int status = 0;
32
33 ADC_init();
34
35 return status;
36}
void ADC_init(void)
Initialize the external memory–mapped ADC interface.
Definition adc.c:12

◆ io_joystick_read_direction()

int io_joystick_read_direction ( struct io_joystick_device * dev,
enum io_joystick_direction * direction )

#include <io.h>

Fetches the direction of a joystick.

Parameters
[in]devThe joystick to read.
[in]directionA buffer for storing the read direction.
Returns
Errno.

Definition at line 66 of file io.c.

67 {
68 int status = 0;
69
71 status = io_joystick_read_position(dev, &pos);
72 if (status) {
73 return status;
74 }
75
76 if (pos.x > (0 - JOYSTICK_THRESHOLD) && pos.x < (0 + JOYSTICK_THRESHOLD) &&
77 pos.y > (0 - JOYSTICK_THRESHOLD) && pos.y < (0 + JOYSTICK_THRESHOLD)) {
78 *direction = NEUTRAL;
79 return status;
80 }
81
82 // Fill inn the remaining directions...
83
84 return status;
85}
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
#define JOYSTICK_THRESHOLD
Definition io.c:16
struct io_joystick_position pos
Definition main.c:58
Represents the position of a joystick relative to center.
Definition io.h:70

◆ io_joystick_read_position()

int io_joystick_read_position ( struct io_joystick_device * dev,
struct io_joystick_position * buffer )

#include <io.h>

Read the position of a joystick as a percentage from 0 in each axis.

Parameters
[in]devThe joystick to read.
[in]bufferA buffer for storing the position value.
Returns
Errno.

Definition at line 38 of file io.c.

39 {
40 struct ADC_meas data;
41
42 ADC_read_all(&data);
43
44 uint8_t raw_x = data.channel[dev->adc_channel_x];
45 uint8_t raw_y = data.channel[dev->adc_channel_y];
46
47 if (raw_x < dev->x_min)
48 raw_x = dev->x_min;
49 if (raw_x > dev->x_max)
50 raw_x = dev->x_max;
51 if (raw_y < dev->y_min)
52 raw_y = dev->y_min;
53 if (raw_y > dev->y_max)
54 raw_y = dev->y_max;
55
56 buffer->x = map(raw_x, dev->x_min, dev->x_max, -127, 127);
57 buffer->y = map(raw_y, dev->y_min, dev->y_max, -127, 127);
58
59 if (buffer->x > -5 && buffer->x < 5)
60 buffer->x = 0;
61 if (buffer->y > -5 && buffer->y < 5)
62 buffer->y = 0;
63
64 return 0;
65}
void ADC_read_all(struct ADC_meas *output)
Perform a full four-channel ADC conversion and return all results.
Definition adc.c:36
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...
Definition utils.c:63
Container for ADC measurement results.
Definition adc.h:20
unsigned int adc_channel_x
Definition io.h:56
unsigned int adc_channel_y
Definition io.h:57

Referenced by io_joystick_read_direction(), and tx_joy_btn().

◆ io_oled_blink()

int io_oled_blink ( struct io_oled_device * dev,
uint8_t blinks )

#include <io.h>

Alternates screen between black and white.

Parameters
[in]devthe OLED device that should be blinked
[in]blinksnumber of blinks newline
Returns
.

Definition at line 450 of file io.c.

450 {
451
452 io_oled_home(dev);
453
454 for (uint8_t blink = 0; blink < 2 * blinks; blink++) {
455 for (uint8_t row = 0; row < 8; row++) {
456 io_oled_goto_line(dev, row);
457 io_oled_goto_column(dev, 0);
458 for (uint8_t col = 0; col < 128; col++) {
459 if (blink % 2 == 0) {
460 _io_oled_write(dev, 0xFF);
461 } else {
462 _io_oled_write(dev, 0x00);
463 }
464 }
465 }
466 _delay_ms(500);
467 }
468 return 0;
469}
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_home(struct io_oled_device *dev)
Loads homescreen to OLED.
Definition io.c:247
int io_oled_goto_column(struct io_oled_device *dev, int column)
Go to specific column in OLED.
Definition io.c:265
static int _io_oled_write(struct io_oled_device *dev, uint8_t data)
Definition io.c:149

◆ io_oled_clear_all()

int io_oled_clear_all ( struct io_oled_device * dev)

#include <io.h>

Clears all lines on the OLED (fills entire display with black).

Parameters
[in]devPointer to the OLED device struct
Returns
Errno (0 = success, -1 = failure)

Definition at line 292 of file io.c.

292 {
293 int status = 0;
294
295 // There are 8 pages (0–7) on a 64-pixel-tall display
296 for (uint8_t line = 0; line < 8; line++) {
297 status = io_oled_clear_line(dev, line);
298 if (status < 0) {
299 return status; // early exit on failure
300 }
301 }
302
303 return 0;
304}
int io_oled_clear_line(struct io_oled_device *dev, int line)
Clear specific line in OLED.
Definition io.c:275

Referenced by brightness_display(), calibrate_joystick_display(), game_over_display(), high_scores_display(), play_game_display(), settings_display(), and welcome_display().

◆ io_oled_clear_line()

int io_oled_clear_line ( struct io_oled_device * dev,
int line )

#include <io.h>

Clear specific line in OLED.

Parameters
[in]devThe OLED who's line is to be cleared
[in]linethe line that to be cleared
Returns
Errno.

Definition at line 275 of file io.c.

275 {
276
277 if (line < 0 || line > 7)
278 return -1;
279 io_oled_goto_line(dev, line);
280 io_oled_goto_column(dev, 0);
281 for (uint8_t x = 0; x < 128; x++) {
282 _io_oled_write(dev, 0x00);
283 }
284 return 0;
285}

Referenced by io_oled_clear_all(), settings_display(), and welcome_display().

◆ io_oled_goto_column()

int io_oled_goto_column ( struct io_oled_device * dev,
int column )

#include <io.h>

Go to specific column in OLED.

Parameters
[in]devThe OLED who's column is to be set
[in]columnthe column which should be set
Returns
Errno.

Definition at line 265 of file io.c.

265 {
266
267 // Columns are split into low/high area commands 0x00-0x0F and 0x10-0x1F
268 _io_oled_cmd(dev, 0x00 | (column & 0x0F)); // lower
269 _io_oled_cmd(dev, 0x10 | ((column >> 4) & 0x0F)); // higher
270 dev->current_column = column; // Update index of current column
271
272 return 0;
273}
static int _io_oled_cmd(struct io_oled_device *dev, uint8_t command)
Definition io.c:141
uint8_t current_column
Definition io.h:49

Referenced by io_oled_blink(), io_oled_clear_line(), io_oled_home(), io_oled_init(), io_oled_pos(), and io_oled_test().

◆ io_oled_goto_line()

int io_oled_goto_line ( struct io_oled_device * dev,
int line )

#include <io.h>

Go to specific line in OLED.

Parameters
[in]devThe OLED who's line is to be set
[in]linethe line to be set
Returns
Errno.

Definition at line 255 of file io.c.

255 {
256
257 if (line > 7)
258 line = 7; // Out of bounds
259 _io_oled_cmd(dev, 0xB0 | (line & 0x07)); // 0xB0-0xB7
260 dev->current_page = line; // Update index of current page
261
262 return 0;
263}
uint8_t current_page
Definition io.h:48

Referenced by io_oled_blink(), io_oled_clear_line(), io_oled_home(), io_oled_init(), io_oled_pos(), and io_oled_test().

◆ io_oled_home()

int io_oled_home ( struct io_oled_device * dev)

#include <io.h>

Loads homescreen to OLED.

Parameters
[in]devThe OLED to be set
Returns
Errno.

Definition at line 247 of file io.c.

247 {
248
249 io_oled_goto_line(dev, 0);
250 io_oled_goto_column(dev, 0);
251
252 return 0;
253}

Referenced by brightness_display(), calibrate_joystick_display(), game_over_display(), high_scores_display(), io_oled_blink(), io_oled_test(), play_game_display(), settings_display(), and welcome_display().

◆ io_oled_init()

int io_oled_init ( struct io_oled_device * dev)

#include <io.h>

Initialise OLED.

Parameters
[in]devThe OLED to be initlaised.
Returns
Errno.

Definition at line 161 of file io.c.

161 {
162 int status = 0;
163
164 while (spi_ready()) {
165 status = spi_init();
166 }
167
168 // --- Configure OLED control pins --- //
169 // Set directions *after* setting desired logic states to avoid glitching
170 DDRB |= (1 << PB4) | (1 << PB1) | (1 << PB2); // Set PB0,PB1,PB2 to outputs
171
172 // --- Hardware reset sequence --- //
173 PORTB &= ~(1 << PB4);
174 _delay_us(5);
175 PORTB |= (1 << PB4);
176 _delay_ms(1);
177
178 // Display OFF
179 _io_oled_cmd(dev, 0xAE);
180
181 // Recommended config for 128x64 OLED, page 19 OLED datasheet
182 _io_oled_cmd(dev, 0xA1); // Segment remap: column address 127->0
183 _io_oled_cmd(dev, 0xC8); // Scan direction: remapped C8 or C0
184
185 _io_oled_cmd(dev, 0xDA); // Common pads hardware
186 _io_oled_cmd(dev, 0x12); // Required parameter for 128x64
187
188 _io_oled_cmd(dev, 0xC8); // Common output scan direciton
189
190 _io_oled_cmd(dev, 0xA8); // Set multiplex ratio
191 _io_oled_cmd(dev, 0x3F); // Multiplex ratio: 63 (64MUX)
192
193 _io_oled_cmd(dev, 0xD5); // set display clock devider ratio
194 _io_oled_cmd(dev, 0x80); // freq.mode
195
196 _io_oled_cmd(dev, 0x81); // Contrast control
197 _io_oled_cmd(dev, 0xFF);
198
199 _io_oled_cmd(dev, 0xD9); // Set precharged period
200 _io_oled_cmd(dev, 0x21);
201
202 _io_oled_cmd(dev, 0x20); // Set memory adressing mode
203 _io_oled_cmd(dev, 0x02); // 0x02 = Page (alternativly 0x00 = Horizontal)
204
205 _io_oled_cmd(dev, 0xDB); // VCOM deselect level mode
206 _io_oled_cmd(dev, 0x30);
207
208 _io_oled_cmd(dev, 0xAD); // Master config
209 _io_oled_cmd(dev, 0x00); // Slave config
210
211 _io_oled_cmd(dev, 0xA4); // Resume to RAM content
212
213 _io_oled_cmd(dev, 0xA6); // Normal display
214
215 // Clear GDDRAM once at init
216 for (uint8_t page = 0; page < 8; page++) {
217 io_oled_goto_line(dev, page);
218 io_oled_goto_column(dev, 0);
219 for (uint8_t x = 0; x < 128; x++) {
220 _io_oled_write(dev, 0x00);
221 }
222 }
223
224 // Display ON
225 _io_oled_cmd(dev, 0xAF);
226
227 return status;
228}

Referenced by menu_init().

◆ io_oled_pos()

int io_oled_pos ( struct io_oled_device * dev,
int row,
int column )

#include <io.h>

Set specific position in OLED.

Parameters
[in]devThe OLED who's position is to be set
[in]rowThe row of the position to be set
[in]collumnthe collumn of the position the be set
Returns
Errno.

Definition at line 306 of file io.c.

306 {
307
308 io_oled_goto_line(dev, line);
309 io_oled_goto_column(dev, column);
310
311 return 0;
312}

Referenced by draw_cursor(), game_over_display(), io_oled_print_arrow(), settings_display(), and welcome_display().

◆ io_oled_print()

int io_oled_print ( struct io_oled_device * dev,
char * text )

#include <io.h>

Write string to OLED.

Parameters
[in]devThe OLED who should print the line
[in]textthe string that should be written to the OLED
Returns
Errno.

◆ io_oled_print_arrow()

int io_oled_print_arrow ( struct io_oled_device * dev,
uint8_t row,
uint8_t col )

#include <io.h>

Prints an arrow at a specified postion.

Parameters
[in]devThe OLED who's britness should be set
[in]rowselect row where the arrow should be placed
[in]columnselect column where the arrow should be placed
Returns
Errno.

Definition at line 330 of file io.c.

330 {
331
332 io_oled_pos(dev, row, col);
333 _io_oled_write(dev, 0b00011000);
334 _io_oled_write(dev, 0b00011000);
335 _io_oled_write(dev, 0b01111110);
336 _io_oled_write(dev, 0b00111100);
337 _io_oled_write(dev, 0b00011000);
338
339 return 0;
340}
int io_oled_pos(struct io_oled_device *dev, int line, int column)
Set specific position in OLED.
Definition io.c:306

◆ io_oled_print_with_font()

int io_oled_print_with_font ( struct io_oled_device * dev,
const struct oled_font * font,
char * text )

#include <io.h>

Prints an arrow at a specified postion.

Parameters
[in]devthe OLED device that should be written to
[in]fontthe specified font, see font.h
[in]textthe string that should be printed to the OLED, has to end in newline
Returns
.

Definition at line 377 of file io.c.

378 {
379 if (!dev || !font || !text)
380 return -1;
381
382 for (char *p = text; *p; ++p) {
383 if (*p == '\n') {
384 continue;
385 }
386 io_oled_write_glyph(dev, font, *p);
387 }
388 return 0;
389}
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

Referenced by brightness_display(), calibrate_joystick_display(), draw_cursor(), game_over_display(), high_scores_display(), io_oled_test(), play_game_display(), settings_display(), and welcome_display().

◆ io_oled_reset()

int io_oled_reset ( struct io_oled_device * dev)

#include <io.h>

Sends command to OLED.

Parameters
[in]devThe commanded OLED.
[in]commandthe hex command (see p27. SSD1309 datasheet)
Returns
Errno.

Sends data to OLED

Parameters
[in]devThe OLED that should receive the data.
[in]datathe data that the OLED should recive
Returns
Errno.

Resets OLED to blank page

Parameters
[in]devThe OLED to be reset.
Returns
Errno.

Definition at line 230 of file io.c.

230 {
231
232 // Display off
233 _io_oled_cmd(dev, 0xAE);
234
235 // --- Hardware reset sequence --- //
236 PORTB &= ~(1 << PB4); // Set PB4 low
237 _delay_us(5); // Wait 5us
238 PORTB |= (1 << PB4); // Set PB4 high
239 _delay_ms(1); // Making sure its restarted before we start sending commands
240
241 // Turn display on
242 _io_oled_cmd(dev, 0xAF);
243
244 return 0;
245}

◆ io_oled_reset_brightness()

int io_oled_reset_brightness ( struct io_oled_device * dev)

#include <io.h>

Reset OLED brightness.

Parameters
[in]devThe OLED who's britness should be set
Returns
Errno.

Definition at line 322 of file io.c.

322 {
323
324 _io_oled_cmd(dev, 0x81);
325 _io_oled_cmd(dev, 0x7F);
326
327 return 0;
328}

◆ io_oled_set_brightness()

int io_oled_set_brightness ( struct io_oled_device * dev,
uint8_t brightness )

#include <io.h>

Set OLED brightness.

Parameters
[in]devThe OLED who's britness should be set
[in]brightnessthe brightness level to be set
Returns
Errno.

Definition at line 314 of file io.c.

314 {
315
316 _io_oled_cmd(dev, 0x81);
317 _io_oled_cmd(dev, brightness);
318
319 return 0;
320}

◆ io_oled_test()

int io_oled_test ( struct io_oled_device * dev)

#include <io.h>

Prints a known image to the OLED to confirm that it can print and navigate the screen.

Parameters
[in]devthe OLED device that should be tested newline
Returns
.

Definition at line 391 of file io.c.

391 {
392
393 io_oled_home(dev);
394
395 // print half a line
396 for (uint8_t i = 0; i < 64; i++) {
397 _io_oled_write(dev, 0xff);
398 }
399
400 io_oled_goto_line(dev, 1); // new line
401
402 // print half a line
403 for (uint8_t i = 0; i < 64; i++) {
404 _io_oled_write(dev, 0xff);
405 }
406
407 io_oled_goto_line(dev, 2); // new line
408 io_oled_goto_column(dev, 0); // new carrige return
409
410 // fill every other column in a row
411 for (uint8_t i = 0; i < 128; i++) {
412 if (i % 2 == 0) {
413 _io_oled_write(dev, 0xff);
414 } else {
415 _io_oled_write(dev, 0x00);
416 }
417 }
418
419 io_oled_goto_line(dev, 3); // new line
420 io_oled_goto_column(dev, 0); // new carrige return
421
422 // fill a row with chess pattern
423 for (uint8_t i = 0; i < 128; i++) {
424 if (i % 2 == 0) {
425 _io_oled_write(dev, 0b01010101);
426 } else {
427 _io_oled_write(dev, 0b10101010);
428 }
429 }
430
431 io_oled_goto_line(dev, 4); // new line
432 io_oled_goto_column(dev, 0); // new carrige return
433 io_oled_print_with_font(dev, &OLED_FONT_8x8, "Text 8x8");
434
435 io_oled_goto_line(dev, 5); // new line
436 io_oled_goto_column(dev, 0); // new carrige return
437 io_oled_print_with_font(dev, &OLED_FONT_5x7, "Text 5x7");
438
439 io_oled_goto_line(dev, 6); // new line
440 io_oled_goto_column(dev, 0); // new carrige return
441 io_oled_print_with_font(dev, &OLED_FONT_4x6, "Text 4x6");
442
443 io_oled_goto_line(dev, 7); // new line
444 io_oled_goto_column(dev, 0); // new carrige return
445 io_oled_print_with_font(dev, &OLED_FONT_8x8, "Test:Complete");
446
447 return 0;
448}
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
static const struct oled_font OLED_FONT_5x7
Predefined 5x7 font for OLED.
Definition io.h:32
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

◆ io_oled_write_command()

int io_oled_write_command ( struct io_oled_device * dev,
uint8_t command )

#include <io.h>

Definition at line 475 of file io.c.

475 {
476 return _io_oled_cmd(dev, command);
477}

◆ io_oled_write_data()

int io_oled_write_data ( struct io_oled_device * dev,
uint8_t data )

#include <io.h>

Definition at line 471 of file io.c.

471 {
472 return _io_oled_write(dev, data);
473}

Referenced by draw_cursor().

◆ io_oled_write_glyph()

uint8_t io_oled_write_glyph ( struct io_oled_device * dev,
const struct oled_font * font,
char character_id )

#include <io.h>

Prints a single glyph in a specifiec font.

Parameters
[in]devthe OLED that should be written to
[in]fontthe specified font, see font.h
[in]character_idthe character that should be written
Returns
Errno.

Definition at line 343 of file io.c.

344 {
345
346 uint8_t start_page = dev->current_page;
347 uint8_t start_column = dev->current_column;
348
349 // --- Draw the glyph on the current page --- //
350 uint8_t glyph_id = 0; // Space as default value
351
352 // Make sure char_id in range
353 if ((uint8_t)character_id >= 32 && (uint8_t)character_id <= 126) {
354 glyph_id = (uint8_t)character_id - 32;
355 }
356
357 // Find glyph in fonts.h
358 uint8_t *base = (uint8_t *)font->table + (glyph_id * font->bytes_per_glyph);
359
360 // Print glyph to oled
361 for (uint8_t c = 0; c < font->bytes_per_glyph; ++c) {
362 // function from <avr/pgmspace.h> that reads from PROGMEM
363 uint8_t col = pgm_read_byte(base + c);
364 _io_oled_write(dev, col);
365 }
366
367 // Add spacing after glyph
368 for (uint8_t s = 0; s < font->spacing; ++s) {
369 _io_oled_write(dev, 0x00);
370 }
371
372 uint8_t total_cols = (uint8_t)(font->bytes_per_glyph + font->spacing);
373
374 return total_cols;
375}
uint8_t spacing
Definition io.h:26
const void * table
Definition io.h:23
uint8_t bytes_per_glyph
Definition io.h:24

Referenced by io_oled_print_with_font().

◆ io_oled_writedata()

volatile int io_oled_writedata ( struct io_oled_device * dev,
int data )

#include <io.h>

Writes data to OLED at current position.

Parameters
[in]devThe OLED where the data should be sent
[in]dataThe data to be sendt to the OLED
Returns
Errno.

Variable Documentation

◆ OLED_FONT_4x6

const struct oled_font OLED_FONT_4x6 = {font4, 4, 6, 1}
static

#include <io.h>

Predefined 4x6 font for OLED.

Definition at line 34 of file io.h.

34{font4, 4, 6, 1};
const unsigned char PROGMEM font4[95][4]
Definition fonts.c:203

Referenced by __attribute__(), and io_oled_test().

◆ OLED_FONT_5x7

const struct oled_font OLED_FONT_5x7 = {font5, 5, 7, 1}
static

#include <io.h>

Predefined 5x7 font for OLED.

Definition at line 32 of file io.h.

32{font5, 5, 7, 1};
const unsigned char PROGMEM font5[95][5]
Definition fonts.c:104

Referenced by io_oled_test().

◆ OLED_FONT_8x8

const struct oled_font OLED_FONT_8x8 = {font8, 8, 8, 1}
static

#include <io.h>

Predefined 8x8 font for OLED.

Definition at line 30 of file io.h.

30{font8, 8, 8, 1};
const unsigned char PROGMEM font8[95][8]
Definition fonts.c:5

Referenced by io_oled_test().