TTK4155 Lab Node 1
Term project in the NTNU course TTK4155 Embedded and Industrial Computer Systems Design
Loading...
Searching...
No Matches
io.c File Reference
#include <avr/pgmspace.h>
#include <stdint.h>
#include <util/delay.h>
#include "adc.h"
#include "can.h"
#include "io.h"
#include "log.h"
#include "spi.h"
#include "uart.h"
#include "utils.h"
#include <stdio.h>

Go to the source code of this file.

Macros

#define JOYSTICK_THRESHOLD   10
#define IO_AVR_TOUCH_PAD   0x01
#define IO_AVR_TOUCH_SLIDER   0x02
#define IO_AVR_JOYSTICK   0x03
#define IO_AVR_BUTTONS   0x04
#define IO_AVR_LED_TOGGLE   0x05
#define IO_AVR_LED_PWM   0x06
#define IO_AVR_INFO   0x07

Functions

 LOG_MODULE_DEFINE ("IO")
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_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)
static int _io_oled_cmd (struct io_oled_device *dev, uint8_t command)
static int _io_oled_write (struct io_oled_device *dev, uint8_t data)
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.
int io_oled_clear_all (struct io_oled_device *dev)
 Clears all lines on the OLED (fills entire display with black).
int io_oled_pos (struct io_oled_device *dev, int line, int column)
 Set specific position in 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)

Macro Definition Documentation

◆ IO_AVR_BUTTONS

#define IO_AVR_BUTTONS   0x04

Definition at line 21 of file io.c.

Referenced by io_avr_buttons_read().

◆ IO_AVR_INFO

#define IO_AVR_INFO   0x07

Definition at line 24 of file io.c.

◆ IO_AVR_JOYSTICK

#define IO_AVR_JOYSTICK   0x03

Definition at line 20 of file io.c.

◆ IO_AVR_LED_PWM

#define IO_AVR_LED_PWM   0x06

Definition at line 23 of file io.c.

Referenced by io_avr_led_set().

◆ IO_AVR_LED_TOGGLE

#define IO_AVR_LED_TOGGLE   0x05

Definition at line 22 of file io.c.

◆ IO_AVR_TOUCH_PAD

#define IO_AVR_TOUCH_PAD   0x01

Definition at line 18 of file io.c.

◆ IO_AVR_TOUCH_SLIDER

#define IO_AVR_TOUCH_SLIDER   0x02

Definition at line 19 of file io.c.

◆ JOYSTICK_THRESHOLD

#define JOYSTICK_THRESHOLD   10

Definition at line 16 of file io.c.

Referenced by io_joystick_read_direction().

Function Documentation

◆ _io_oled_cmd()

int _io_oled_cmd ( struct io_oled_device * dev,
uint8_t command )
static

Definition at line 141 of file io.c.

141 {
142 PORTB &= ~(1 << PB1); // D/!C=0
143 // PB2 DISP_CS Low, Chipselect is driven by SPI
144 spi_send(&dev->spi, command);
145 //_delay_us(3);
146 return 0;
147}
int spi_send(enum spi_slave *slave, unsigned char data)
Send a single byte to a slave.
Definition spi.c:86
enum spi_slave spi
Definition io.h:47

Referenced by io_oled_goto_column(), io_oled_goto_line(), io_oled_init(), io_oled_reset(), io_oled_reset_brightness(), io_oled_set_brightness(), and io_oled_write_command().

◆ _io_oled_write()

int _io_oled_write ( struct io_oled_device * dev,
uint8_t data )
static

Definition at line 149 of file io.c.

149 {
150 PORTB |= (1 << PB1); // D/!C set high
151 // PB2 DISP_CS Low, Chipselect is driven by SPI
152 spi_send(&dev->spi, data);
153 //_delay_us(3);
154 dev->current_column++;
155
156 return 0;
157}
uint8_t current_column
Definition io.h:49

Referenced by io_oled_blink(), io_oled_clear_line(), io_oled_init(), io_oled_print_arrow(), io_oled_test(), io_oled_write_data(), and io_oled_write_glyph().

◆ LOG_MODULE_DEFINE()

LOG_MODULE_DEFINE ( "IO" )