Skip to content

Commit

Permalink
Add unprotected driver for StickIt!-LedDigits module.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanbulck committed Sep 5, 2017
1 parent 2e72ba6 commit abab5a6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(HEADERS
sancus_support/tsc.h
sancus_support/tools.h
sancus_support/uart.h
sancus_support/led_digits.h
sancus_support/link.h
sancus_support/packet.h
sancus_support/sm_io.h
Expand Down
7 changes: 7 additions & 0 deletions include/sancus_support/led_digits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef SANCUS_SUPPORT_LED_H_INC
#define SANCUS_SUPPORT_LED_H_INC

void led_digits_update(char c1, char c2, char c3, char c4,
char c5, char c6, char c7, char c8);

#endif
7 changes: 5 additions & 2 deletions src/dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ add_library(obj-ps2 OBJECT ps2.c)
add_library(obj-pmodcls OBJECT pmodcls.c)
add_library(obj-pmodkypd OBJECT pmodkypd.c)
add_library(obj-spi OBJECT spi.c)
add_library(obj-led OBJECT led_digits.c)

add_library(dev-timer STATIC $<TARGET_OBJECTS:obj-timer>)
add_library(dev-uart STATIC $<TARGET_OBJECTS:obj-uart>)
add_library(dev-ps2 STATIC $<TARGET_OBJECTS:obj-ps2>)
add_library(dev-pmodcls STATIC $<TARGET_OBJECTS:obj-pmodcls>)
add_library(dev-pmodkypd STATIC $<TARGET_OBJECTS:obj-pmodkypd>)
add_library(dev-spi STATIC $<TARGET_OBJECTS:obj-spi>)
add_library(dev-led STATIC $<TARGET_OBJECTS:obj-led>)

add_library(dev STATIC $<TARGET_OBJECTS:obj-timer>
$<TARGET_OBJECTS:obj-uart>
$<TARGET_OBJECTS:obj-ps2>
$<TARGET_OBJECTS:obj-pmodcls>
$<TARGET_OBJECTS:obj-pmodkypd>
$<TARGET_OBJECTS:obj-spi>)
$<TARGET_OBJECTS:obj-spi>
$<TARGET_OBJECTS:obj-led>)

install(TARGETS dev-timer dev-uart dev-ps2 dev-pmodcls dev-pmodkypd dev-spi dev
install(TARGETS dev-timer dev-uart dev-ps2 dev-pmodcls dev-pmodkypd dev-spi dev-led dev
EXPORT ExportTargets
ARCHIVE DESTINATION ${INSTALL_LIBS_DIR})
56 changes: 56 additions & 0 deletions src/dev/led_digits.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "led_digits.h"
#include <stdint.h>

// MMIO registers for led digit segments:
// (MSB-1) g f e d c b a (LSB)
#define LED_BASE 0x0090
#define LED1 *(volatile uint8_t*)(LED_BASE+0)
#define LED2 *(volatile uint8_t*)(LED_BASE+1)
#define LED3 *(volatile uint8_t*)(LED_BASE+2)
#define LED4 *(volatile uint8_t*)(LED_BASE+3)
#define LED5 *(volatile uint8_t*)(LED_BASE+4)
#define LED6 *(volatile uint8_t*)(LED_BASE+5)
#define LED7 *(volatile uint8_t*)(LED_BASE+6)
#define LED8 *(volatile uint8_t*)(LED_BASE+7)
#define _BAD 0x00

const uint8_t led_digit_map[] = {
/*0=*/ 0x3f, 0x06, 0x5b, 0x4f, 0x66,
/*5=*/ 0x6d, 0x7d, 0x07, 0x7f, 0x6f
};

const uint8_t led_alpha_map[] = {
/*A=*/ 0x77, 0x7c, 0x39, 0x5e, 0x79,
/*F=*/ 0x71, 0x3d, 0x74, 0x30, 0x1e,
/*K=*/ _BAD, 0x38, _BAD, 0x54, 0x5c,
/*P=*/ 0x73, _BAD, 0x50, 0x6d, 0x78,
/*U=*/ 0x1c, _BAD, _BAD, _BAD, 0x6e,
/*Z=*/ _BAD
};

uint8_t led_from_char(char c)
{
if (c >= '0' && c <= '9')
return led_digit_map[c-'0'];

if (c >= 'A' && c <= 'Z')
c = 'a' + (c-'A');

if (c >= 'a' && c <= 'z')
return led_alpha_map[c-'a'];

return _BAD;
}

void led_digits_update(char c1, char c2, char c3, char c4,
char c5, char c6, char c7, char c8)
{
LED1 = led_from_char(c1);
LED2 = led_from_char(c2);
LED3 = led_from_char(c3);
LED4 = led_from_char(c4);
LED5 = led_from_char(c5);
LED6 = led_from_char(c6);
LED7 = led_from_char(c7);
LED8 = led_from_char(c8);
}

0 comments on commit abab5a6

Please sign in to comment.