add firmware folder

This commit is contained in:
Julian Daube 2019-02-06 23:22:59 +01:00 committed by Julian Daube
parent b1ab788953
commit 6a946f09ac
10 changed files with 102154 additions and 0 deletions

View File

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.0.0)
set(AVR_MCU attiny84a)
include(avr-toolchain.cmake)
project(DSPLAB_display_firmware C)
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-O3")
add_avr_executable(DSPLAB_display_firmware main.c)

View File

@ -0,0 +1,85 @@
# give info about target
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR avr)
# find tools
find_program(AVR_CC avr-gcc)
find_program(AVR_CXX avr-g++)
find_program(AVR_OBJCOPY avr-objcopy)
find_program(AVR_SIZE_TOOL avr-size)
# set compiler (globally)
SET(CMAKE_C_COMPILER ${AVR_CC})
SET(CMAKE_CXX_COMPILER ${AVR_CXX})
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
add_definitions(-mmcu=${AVR_MCU} -DF_CPU=8000000 --std=c99)
function(add_avr_executable EXECUTABLE_NAME)
if(NOT ARGN)
message(FATAL_ERROR "No source files given for ${EXECUTABLE_NAME}.")
endif(NOT ARGN)
# set file names
set(elf_file ${EXECUTABLE_NAME})
set(hex_file ${EXECUTABLE_NAME}.hex)
set(lst_file ${EXECUTABLE_NAME}.lst)
set(map_file ${EXECUTABLE_NAME}.map)
set(eeprom_image ${EXECUTABLE_NAME}_eeprom.hex)
# elf file
add_executable(${elf_file} EXCLUDE_FROM_ALL ${ARGN})
set_target_properties(
${elf_file}
PROPERTIES
COMPILE_FLAGS "-mmcu=${AVR_MCU}"
LINK_FLAGS "-mmcu=${AVR_MCU} -Wl,--gc-sections -mrelax -Wl,-Map,${map_file}"
)
add_custom_command(
OUTPUT ${hex_file}
COMMAND
${AVR_OBJCOPY} -j .text -j .data -O ihex ${elf_file} ${hex_file}
COMMAND
${AVR_SIZE_TOOL} ${AVR_SIZE_ARGS} ${elf_file}
DEPENDS ${elf_file}
)
add_custom_command(
OUTPUT ${lst_file}
COMMAND
${AVR_OBJDUMP} -d ${elf_file} > ${lst_file}
DEPENDS ${elf_file}
)
# eeprom
add_custom_command(
OUTPUT ${eeprom_image}
COMMAND
${AVR_OBJCOPY} -j .eeprom --set-section-flags=.eeprom=alloc,load
--change-section-lma .eeprom=0 --no-change-warnings
-O ihex ${elf_file} ${eeprom_image}
DEPENDS ${elf_file}
)
add_custom_target(
build_${EXECUTABLE_NAME}
ALL
DEPENDS ${hex_file} ${lst_file} ${eeprom_image}
)
set_target_properties(
build_${EXECUTABLE_NAME}
PROPERTIES
OUTPUT_NAME "${elf_file}"
)
# clean
get_directory_property(clean_files ADDITIONAL_MAKE_CLEAN_FILES)
set_directory_properties(
PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${map_file}"
)
endfunction(add_avr_executable)

50482
firmware/display/doc8183.pdf Normal file

File diff suppressed because one or more lines are too long

441
firmware/display/font.h Normal file
View File

@ -0,0 +1,441 @@
/*
* font.h
*
* Created on: 06.02.2019
* Author: julian
*/
#ifndef FONT_H_
#define FONT_H_
#include <avr/pgmspace.h>
#define FONT_WIDTH 0x0A // Width: 10
#define FONT_HEIGHT 0x0C // Height: 12
#define FONT_START 0x20 // First Char: 32
#define FONT_END 0xE0 // Numbers of Chars: 224
// Created by http://oleddisplay.squix.ch/ Consider a donation
// In case of problems make sure that you are using the font file with the correct version!
const char Fonttable[] PROGMEM = {
// Jump Table:
0xFF, 0xFF, 0x00, 0x03, // 32:65535
0x00, 0x00, 0x03, 0x02, // 33:0
0x00, 0x03, 0x03, 0x02, // 34:3
0x00, 0x06, 0x07, 0x04, // 35:6
0x00, 0x0D, 0x05, 0x03, // 36:13
0x00, 0x12, 0x05, 0x03, // 37:18
0x00, 0x17, 0x09, 0x05, // 38:23
0x00, 0x20, 0x01, 0x01, // 39:32
0x00, 0x21, 0x05, 0x03, // 40:33
0x00, 0x26, 0x03, 0x03, // 41:38
0x00, 0x29, 0x05, 0x03, // 42:41
0x00, 0x2E, 0x07, 0x04, // 43:46
0x00, 0x35, 0x01, 0x01, // 44:53
0x00, 0x36, 0x07, 0x04, // 45:54
0x00, 0x3D, 0x01, 0x01, // 46:61
0x00, 0x3E, 0x07, 0x04, // 47:62
0x00, 0x45, 0x07, 0x05, // 48:69
0x00, 0x4C, 0x04, 0x03, // 49:76
0x00, 0x50, 0x07, 0x04, // 50:80
0x00, 0x57, 0x07, 0x05, // 51:87
0x00, 0x5E, 0x09, 0x05, // 52:94
0x00, 0x67, 0x07, 0x04, // 53:103
0x00, 0x6E, 0x07, 0x04, // 54:110
0x00, 0x75, 0x09, 0x05, // 55:117
0x00, 0x7E, 0x07, 0x05, // 56:126
0x00, 0x85, 0x07, 0x04, // 57:133
0x00, 0x8C, 0x01, 0x01, // 58:140
0x00, 0x8D, 0x01, 0x01, // 59:141
0x00, 0x8E, 0x07, 0x04, // 60:142
0x00, 0x95, 0x07, 0x04, // 61:149
0x00, 0x9C, 0x07, 0x04, // 62:156
0x00, 0xA3, 0x05, 0x03, // 63:163
0x00, 0xA8, 0x09, 0x05, // 64:168
0x00, 0xB1, 0x0B, 0x06, // 65:177
0x00, 0xBC, 0x0B, 0x06, // 66:188
0x00, 0xC7, 0x0B, 0x06, // 67:199
0x00, 0xD2, 0x0B, 0x06, // 68:210
0x00, 0xDD, 0x07, 0x04, // 69:221
0x00, 0xE4, 0x07, 0x04, // 70:228
0x00, 0xEB, 0x0C, 0x07, // 71:235
0x00, 0xF7, 0x0B, 0x06, // 72:247
0x01, 0x02, 0x04, 0x02, // 73:258
0x01, 0x06, 0x07, 0x04, // 74:262
0x01, 0x0D, 0x09, 0x05, // 75:269
0x01, 0x16, 0x08, 0x04, // 76:278
0x01, 0x1E, 0x0F, 0x08, // 77:286
0x01, 0x2D, 0x0B, 0x06, // 78:301
0x01, 0x38, 0x0B, 0x06, // 79:312
0x01, 0x43, 0x09, 0x05, // 80:323
0x01, 0x4C, 0x0C, 0x07, // 81:332
0x01, 0x58, 0x0B, 0x06, // 82:344
0x01, 0x63, 0x08, 0x04, // 83:355
0x01, 0x6B, 0x07, 0x04, // 84:363
0x01, 0x72, 0x09, 0x05, // 85:370
0x01, 0x7B, 0x0B, 0x06, // 86:379
0x01, 0x86, 0x0F, 0x08, // 87:390
0x01, 0x95, 0x0C, 0x06, // 88:405
0x01, 0xA1, 0x0C, 0x06, // 89:417
0x01, 0xAD, 0x0A, 0x06, // 90:429
0x01, 0xB7, 0x04, 0x02, // 91:439
0x01, 0xBB, 0x08, 0x04, // 92:443
0x01, 0xC3, 0x04, 0x02, // 93:451
0x01, 0xC7, 0x05, 0x04, // 94:455
0x01, 0xCC, 0x0F, 0x08, // 95:460
0x01, 0xDB, 0x07, 0x06, // 96:475
0x01, 0xE2, 0x09, 0x05, // 97:482
0x01, 0xEB, 0x09, 0x05, // 98:491
0x01, 0xF4, 0x07, 0x05, // 99:500
0x01, 0xFB, 0x0C, 0x06, // 100:507
0x02, 0x07, 0x07, 0x05, // 101:519
0x02, 0x0E, 0x06, 0x03, // 102:526
0x02, 0x14, 0x08, 0x04, // 103:532
0x02, 0x1C, 0x07, 0x04, // 104:540
0x02, 0x23, 0x03, 0x02, // 105:547
0x02, 0x26, 0x02, 0x02, // 106:550
0x02, 0x28, 0x07, 0x04, // 107:552
0x02, 0x2F, 0x01, 0x02, // 108:559
0x02, 0x30, 0x0D, 0x07, // 109:560
0x02, 0x3D, 0x07, 0x05, // 110:573
0x02, 0x44, 0x09, 0x05, // 111:580
0x02, 0x4D, 0x09, 0x05, // 112:589
0x02, 0x56, 0x0A, 0x05, // 113:598
0x02, 0x60, 0x07, 0x04, // 114:608
0x02, 0x67, 0x07, 0x04, // 115:615
0x02, 0x6E, 0x06, 0x03, // 116:622
0x02, 0x74, 0x07, 0x05, // 117:628
0x02, 0x7B, 0x07, 0x04, // 118:635
0x02, 0x82, 0x0D, 0x07, // 119:642
0x02, 0x8F, 0x07, 0x04, // 120:655
0x02, 0x96, 0x0A, 0x05, // 121:662
0x02, 0xA0, 0x07, 0x04, // 122:672
0x02, 0xA7, 0x06, 0x03, // 123:679
0x02, 0xAD, 0x02, 0x01, // 124:685
0x02, 0xAF, 0x05, 0x03, // 125:687
0x02, 0xB4, 0x07, 0x04, // 126:692
0xFF, 0xFF, 0x00, 0x03, // 127:65535
0xFF, 0xFF, 0x00, 0x03, // 128:65535
0xFF, 0xFF, 0x00, 0x03, // 129:65535
0xFF, 0xFF, 0x00, 0x03, // 130:65535
0xFF, 0xFF, 0x00, 0x03, // 131:65535
0xFF, 0xFF, 0x00, 0x03, // 132:65535
0xFF, 0xFF, 0x00, 0x03, // 133:65535
0xFF, 0xFF, 0x00, 0x03, // 134:65535
0xFF, 0xFF, 0x00, 0x03, // 135:65535
0xFF, 0xFF, 0x00, 0x03, // 136:65535
0xFF, 0xFF, 0x00, 0x03, // 137:65535
0xFF, 0xFF, 0x00, 0x03, // 138:65535
0xFF, 0xFF, 0x00, 0x03, // 139:65535
0xFF, 0xFF, 0x00, 0x03, // 140:65535
0xFF, 0xFF, 0x00, 0x03, // 141:65535
0xFF, 0xFF, 0x00, 0x03, // 142:65535
0xFF, 0xFF, 0x00, 0x03, // 143:65535
0xFF, 0xFF, 0x00, 0x03, // 144:65535
0xFF, 0xFF, 0x00, 0x03, // 145:65535
0xFF, 0xFF, 0x00, 0x03, // 146:65535
0xFF, 0xFF, 0x00, 0x03, // 147:65535
0xFF, 0xFF, 0x00, 0x03, // 148:65535
0xFF, 0xFF, 0x00, 0x03, // 149:65535
0xFF, 0xFF, 0x00, 0x03, // 150:65535
0xFF, 0xFF, 0x00, 0x03, // 151:65535
0xFF, 0xFF, 0x00, 0x03, // 152:65535
0xFF, 0xFF, 0x00, 0x03, // 153:65535
0xFF, 0xFF, 0x00, 0x03, // 154:65535
0xFF, 0xFF, 0x00, 0x03, // 155:65535
0xFF, 0xFF, 0x00, 0x03, // 156:65535
0xFF, 0xFF, 0x00, 0x03, // 157:65535
0xFF, 0xFF, 0x00, 0x03, // 158:65535
0xFF, 0xFF, 0x00, 0x03, // 159:65535
0xFF, 0xFF, 0x00, 0x03, // 160:65535
0x02, 0xBB, 0x03, 0x02, // 161:699
0x02, 0xBE, 0x05, 0x03, // 162:702
0x02, 0xC3, 0x07, 0x04, // 163:707
0x02, 0xCA, 0x07, 0x04, // 164:714
0x02, 0xD1, 0x07, 0x04, // 165:721
0x02, 0xD8, 0x01, 0x01, // 166:728
0x02, 0xD9, 0x06, 0x03, // 167:729
0x02, 0xDF, 0x07, 0x06, // 168:735
0x02, 0xE6, 0x07, 0x04, // 169:742
0x02, 0xED, 0x03, 0x02, // 170:749
0x02, 0xF0, 0x05, 0x03, // 171:752
0x02, 0xF5, 0x07, 0x04, // 172:757
0x02, 0xFC, 0x07, 0x04, // 173:764
0x03, 0x03, 0x07, 0x04, // 174:771
0x03, 0x0A, 0x07, 0x06, // 175:778
0x03, 0x11, 0x01, 0x02, // 176:785
0x03, 0x12, 0x07, 0x04, // 177:786
0x03, 0x19, 0x05, 0x03, // 178:793
0x03, 0x1E, 0x03, 0x03, // 179:798
0x03, 0x21, 0x07, 0x06, // 180:801
0x03, 0x28, 0x07, 0x04, // 181:808
0x03, 0x2F, 0x09, 0x05, // 182:815
0x03, 0x38, 0x01, 0x01, // 183:824
0x03, 0x39, 0x08, 0x06, // 184:825
0x03, 0x41, 0x01, 0x02, // 185:833
0x03, 0x42, 0x05, 0x03, // 186:834
0x03, 0x47, 0x05, 0x03, // 187:839
0x03, 0x4C, 0x0A, 0x05, // 188:844
0x03, 0x56, 0x0A, 0x05, // 189:854
0x03, 0x60, 0x0C, 0x06, // 190:864
0x03, 0x6C, 0x05, 0x03, // 191:876
0x03, 0x71, 0x0B, 0x06, // 192:881
0x03, 0x7C, 0x0B, 0x06, // 193:892
0x03, 0x87, 0x0B, 0x06, // 194:903
0x03, 0x92, 0x0B, 0x06, // 195:914
0x03, 0x9D, 0x0B, 0x06, // 196:925
0x03, 0xA8, 0x0B, 0x06, // 197:936
0x03, 0xB3, 0x13, 0x0A, // 198:947
0x03, 0xC6, 0x0B, 0x06, // 199:966
0x03, 0xD1, 0x07, 0x04, // 200:977
0x03, 0xD8, 0x07, 0x04, // 201:984
0x03, 0xDF, 0x07, 0x04, // 202:991
0x03, 0xE6, 0x07, 0x04, // 203:998
0x03, 0xED, 0x04, 0x02, // 204:1005
0x03, 0xF1, 0x04, 0x02, // 205:1009
0x03, 0xF5, 0x04, 0x02, // 206:1013
0x03, 0xF9, 0x04, 0x02, // 207:1017
0x03, 0xFD, 0x0B, 0x06, // 208:1021
0x04, 0x08, 0x0B, 0x06, // 209:1032
0x04, 0x13, 0x0B, 0x06, // 210:1043
0x04, 0x1E, 0x0B, 0x06, // 211:1054
0x04, 0x29, 0x0B, 0x06, // 212:1065
0x04, 0x34, 0x0B, 0x06, // 213:1076
0x04, 0x3F, 0x0B, 0x06, // 214:1087
0x04, 0x4A, 0x05, 0x03, // 215:1098
0x04, 0x4F, 0x0B, 0x06, // 216:1103
0x04, 0x5A, 0x09, 0x05, // 217:1114
0x04, 0x63, 0x09, 0x05, // 218:1123
0x04, 0x6C, 0x09, 0x05, // 219:1132
0x04, 0x75, 0x09, 0x05, // 220:1141
0x04, 0x7E, 0x0C, 0x06, // 221:1150
0x04, 0x8A, 0x0B, 0x06, // 222:1162
0x04, 0x95, 0x09, 0x05, // 223:1173
0x04, 0x9E, 0x09, 0x05, // 224:1182
0x04, 0xA7, 0x09, 0x05, // 225:1191
0x04, 0xB0, 0x09, 0x05, // 226:1200
0x04, 0xB9, 0x09, 0x05, // 227:1209
0x04, 0xC2, 0x09, 0x05, // 228:1218
0x04, 0xCB, 0x09, 0x05, // 229:1227
0x04, 0xD4, 0x0F, 0x08, // 230:1236
0x04, 0xE3, 0x07, 0x04, // 231:1251
0x04, 0xEA, 0x07, 0x05, // 232:1258
0x04, 0xF1, 0x07, 0x05, // 233:1265
0x04, 0xF8, 0x07, 0x05, // 234:1272
0x04, 0xFF, 0x07, 0x05, // 235:1279
0x05, 0x06, 0x03, 0x02, // 236:1286
0x05, 0x09, 0x03, 0x02, // 237:1289
0x05, 0x0C, 0x03, 0x02, // 238:1292
0x05, 0x0F, 0x03, 0x02, // 239:1295
0x05, 0x12, 0x07, 0x04, // 240:1298
0x05, 0x19, 0x09, 0x05, // 241:1305
0x05, 0x22, 0x09, 0x05, // 242:1314
0x05, 0x2B, 0x09, 0x05, // 243:1323
0x05, 0x34, 0x09, 0x05, // 244:1332
0x05, 0x3D, 0x09, 0x05, // 245:1341
0x05, 0x46, 0x09, 0x05, // 246:1350
0x05, 0x4F, 0x07, 0x04, // 247:1359
0x05, 0x56, 0x09, 0x05, // 248:1366
0x05, 0x5F, 0x07, 0x05, // 249:1375
0x05, 0x66, 0x07, 0x05, // 250:1382
0x05, 0x6D, 0x07, 0x05, // 251:1389
0x05, 0x74, 0x07, 0x05, // 252:1396
0x05, 0x7B, 0x0A, 0x05, // 253:1403
0x05, 0x85, 0x0B, 0x06, // 254:1413
0x05, 0x90, 0x0A, 0x05, // 255:1424
// Font Data:
0x60,0x01,0x18, // 33
0x00,0x00,0x18, // 34
0x50,0x00,0xF8,0x00,0xF0,0x00,0x58, // 35
0x58,0x00,0xAC,0x01,0xF0, // 36
0x18,0x01,0xD8,0x00,0xB8, // 37
0xE0,0x00,0x38,0x01,0x34,0x01,0xE8,0x00,0x34, // 38
0x18, // 39
0xE0,0x00,0x18,0x03,0x04, // 40
0x88,0x01,0x70, // 41
0x30,0x00,0x18,0x00,0x30, // 42
0x20,0x00,0xF8,0x00,0x20,0x00,0x20, // 43
0x80, // 44
0x20,0x00,0x20,0x00,0x20,0x00,0x20, // 45
0x80, // 46
0x00,0x01,0xC0,0x00,0x30,0x00,0x0C, // 47
0x78,0x00,0x84,0x00,0x84,0x00,0x78, // 48
0x20,0x00,0xF8,0x01, // 49
0xB0,0x00,0xC8,0x00,0x48,0x00,0xB8, // 50
0x98,0x00,0x24,0x01,0x24,0x01,0xF8, // 51
0x40,0x00,0x38,0x00,0x20,0x00,0xFC,0x01,0x40, // 52
0x40,0x00,0xB8,0x00,0x98,0x00,0x78, // 53
0x70,0x00,0xA8,0x00,0xA8,0x00,0xF0, // 54
0x08,0x00,0x88,0x00,0x68,0x00,0x28,0x00,0x38, // 55
0x40,0x00,0xB8,0x00,0xA8,0x00,0x78, // 56
0xB0,0x00,0xA8,0x00,0x68,0x00,0x30, // 57
0xA0, // 58
0xA0, // 59
0x40,0x00,0x60,0x00,0x90,0x00,0x90, // 60
0xA0,0x00,0xA0,0x00,0xA0,0x00,0xA0, // 61
0x50,0x00,0x50,0x00,0x20,0x00,0x20, // 62
0x78,0x00,0x64,0x01,0x24, // 63
0x70,0x00,0xB8,0x00,0xB8,0x00,0xA8,0x00,0x70, // 64
0x40,0x00,0xB8,0x00,0x24,0x00,0xA4,0x00,0x78,0x00,0x20, // 65
0xF4,0x01,0xF8,0x01,0x84,0x00,0xE4,0x00,0x64,0x00,0x18, // 66
0x70,0x00,0x90,0x00,0x88,0x00,0x88,0x00,0x98,0x00,0x58, // 67
0x08,0x01,0xFC,0x01,0x08,0x01,0x08,0x01,0x90,0x00,0x70, // 68
0x60,0x00,0x98,0x00,0x98,0x00,0x50, // 69
0x04,0x00,0xFC,0x01,0x44,0x00,0x04, // 70
0x70,0x00,0xC8,0x00,0x84,0x00,0x84,0x01,0x84,0x02,0xF8,0x01, // 71
0x44,0x00,0xF8,0x01,0x40,0x00,0x40,0x00,0x40,0x00,0xFC, // 72
0x00,0x00,0xF8,0x01, // 73
0x80,0x01,0x40,0x01,0x04,0x01,0xF8, // 74
0x60,0x00,0xF8,0x01,0x20,0x00,0x70,0x00,0x8C, // 75
0x84,0x01,0xF8,0x00,0x80,0x00,0x00,0x01, // 76
0x00,0x00,0x70,0x00,0x88,0x00,0x78,0x00,0x70,0x00,0x08,0x00,0x88,0x00,0x70, // 77
0x00,0x00,0xF8,0x01,0x18,0x00,0x04,0x00,0xC4,0x01,0x3C, // 78
0x78,0x00,0x8C,0x00,0x84,0x00,0x84,0x00,0xCC,0x00,0x78, // 79
0x1C,0x00,0xFC,0x01,0x24,0x00,0x24,0x00,0x18, // 80
0x00,0x00,0x78,0x00,0x84,0x00,0x84,0x00,0xC4,0x00,0x78,0x01, // 81
0x18,0x00,0xFC,0x01,0x24,0x00,0x24,0x00,0xE4,0x01,0x18, // 82
0x80,0x00,0x58,0x01,0x28,0x01,0xD0,0x01, // 83
0x10,0x00,0x08,0x00,0xF8,0x01,0x08, // 84
0x00,0x00,0x78,0x00,0x80,0x00,0x80,0x00,0x78, // 85
0x0C,0x00,0x10,0x00,0xE0,0x03,0xA0,0x03,0x18,0x00,0x04, // 86
0x00,0x00,0xF0,0x00,0x88,0x00,0xE0,0x00,0x80,0x00,0x80,0x00,0xC0,0x00,0x78, // 87
0x00,0x00,0x8C,0x01,0x50,0x00,0x20,0x00,0xD0,0x00,0x0C,0x01, // 88
0x00,0x00,0xF0,0x00,0x88,0x0E,0x40,0x09,0xF8,0x07,0x00,0x02, // 89
0x10,0x01,0x10,0x01,0xC8,0x00,0xA8,0x00,0x38,0x01, // 90
0x00,0x00,0xFE,0x01, // 91
0x0C,0x00,0x10,0x00,0x60,0x00,0x80,0x01, // 92
0x04,0x01,0xFC,0x01, // 93
0x30,0x00,0x08,0x00,0x30, // 94
0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80, // 95
0x00,0x00,0x00,0x00,0x00,0x00,0x08, // 96
0x60,0x00,0x90,0x00,0x90,0x00,0x90,0x00,0xF0, // 97
0xFC,0x01,0x20,0x01,0x10,0x01,0x10,0x01,0xE0, // 98
0xE0,0x00,0x10,0x01,0x10,0x01,0xA0, // 99
0xC0,0x00,0x20,0x01,0x20,0x01,0xA0,0x00,0xFC,0x00,0x00,0x01, // 100
0x60,0x00,0xD0,0x00,0xD0,0x00,0x70, // 101
0x10,0x00,0xF8,0x00,0x04,0x01, // 102
0x60,0x00,0x50,0x07,0xD0,0x05,0x70,0x03, // 103
0xFC,0x01,0x10,0x00,0x10,0x01,0xF0, // 104
0x00,0x00,0x78, // 105
0xF4,0x03, // 106
0xFC,0x00,0x60,0x00,0x60,0x00,0x90, // 107
0xFC, // 108
0x10,0x00,0xE0,0x00,0x10,0x00,0xF0,0x00,0x20,0x00,0x90,0x00,0x70, // 109
0xE0,0x00,0x10,0x00,0x90,0x00,0x70, // 110
0x60,0x00,0x90,0x00,0x90,0x00,0x90,0x00,0x60, // 111
0xD0,0x03,0xE0,0x03,0x90,0x00,0x90,0x00,0x60, // 112
0xE0,0x00,0x90,0x00,0x90,0x00,0xF0,0x03,0x80,0x04, // 113
0x00,0x00,0xF0,0x01,0x10,0x00,0x30, // 114
0x30,0x00,0x50,0x00,0xD0,0x00,0xE0, // 115
0x10,0x00,0xF8,0x00,0x14,0x01, // 116
0x70,0x00,0x80,0x00,0x80,0x00,0x70, // 117
0x30,0x00,0xC0,0x00,0x40,0x00,0x30, // 118
0xF0,0x00,0x80,0x00,0x80,0x00,0xF0,0x00,0x80,0x00,0x90,0x00,0x70, // 119
0xA0,0x00,0x40,0x00,0xB0,0x00,0x80, // 120
0x70,0x00,0x40,0x0F,0xA0,0x08,0xF0,0x07,0x80,0x01, // 121
0xA0,0x00,0xD0,0x00,0xD0,0x00,0xF0, // 122
0x20,0x00,0x20,0x00,0xFC,0x01, // 123
0xF8,0x01, // 124
0x04,0x01,0xF8,0x00,0x20, // 125
0x60,0x00,0x20,0x00,0x20,0x00,0x20, // 126
0x00,0x00,0xF8, // 161
0x70,0x00,0xDC,0x00,0x78, // 162
0x20,0x00,0xF8,0x00,0xA8,0x00,0xB0, // 163
0x78,0x00,0x48,0x00,0x48,0x00,0x78, // 164
0x10,0x00,0xE0,0x00,0xB8,0x00,0xA0, // 165
0xD8, // 166
0x7C,0x00,0x94,0x01,0xE8,0x01, // 167
0x00,0x00,0x00,0x00,0x08,0x00,0x08, // 168
0x30,0x00,0x78,0x00,0x78,0x00,0x30, // 169
0x30,0x00,0x30, // 170
0x60,0x00,0xF0,0x00,0x90, // 171
0x20,0x00,0x20,0x00,0x20,0x00,0xE0, // 172
0x20,0x00,0x20,0x00,0x20,0x00,0x20, // 173
0x30,0x00,0x78,0x00,0x78,0x00,0x30, // 174
0x00,0x00,0x00,0x00,0x08,0x00,0x08, // 175
0x08, // 176
0xA0,0x00,0xB8,0x00,0x90,0x00,0x90, // 177
0x28,0x00,0x38,0x00,0x20, // 178
0x38,0x00,0x38, // 179
0x00,0x00,0x00,0x00,0x00,0x00,0x08, // 180
0xF0,0x03,0x80,0x00,0x80,0x00,0x70, // 181
0x30,0x00,0x48,0x00,0xF8,0x00,0x78,0x00,0x88, // 182
0x20, // 183
0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x01, // 184
0x38, // 185
0x30,0x00,0x30,0x00,0x30, // 186
0x90,0x00,0xF0,0x00,0x60, // 187
0x38,0x00,0xC0,0x00,0xB0,0x00,0xC8,0x00,0xE0,0x01, // 188
0x38,0x00,0xC0,0x00,0x70,0x01,0xA8,0x00,0x40,0x01, // 189
0x30,0x00,0x38,0x00,0xC0,0x00,0x30,0x00,0x88,0x00,0xE0,0x01, // 190
0xC0,0x01,0x54,0x01,0xF0, // 191
0x40,0x00,0xB8,0x00,0x24,0x00,0xA6,0x00,0x78,0x00,0x20, // 192
0x40,0x00,0xB8,0x00,0x24,0x00,0xA4,0x00,0x7A,0x00,0x20, // 193
0x40,0x00,0xB8,0x00,0x26,0x00,0xA4,0x00,0x78,0x00,0x20, // 194
0x40,0x00,0xB8,0x00,0x26,0x00,0xA6,0x00,0x7A,0x00,0x22, // 195
0x40,0x00,0xB8,0x00,0x26,0x00,0xA6,0x00,0x78,0x00,0x20, // 196
0x40,0x00,0xB0,0x00,0x28,0x00,0x26,0x00,0xF8,0x00,0x20, // 197
0x60,0x00,0xD8,0x00,0x44,0x00,0x44,0x00,0x4C,0x00,0xF8,0x00,0xC8,0x00,0xC8,0x00,0x44,0x00,0x20, // 198
0x70,0x00,0xC8,0x00,0x84,0x03,0x84,0x03,0x9C,0x00,0x58, // 199
0x60,0x00,0x98,0x00,0x9A,0x00,0x50, // 200
0x60,0x00,0x98,0x00,0x98,0x00,0x52, // 201
0x60,0x00,0x98,0x00,0x9A,0x00,0x52, // 202
0x60,0x00,0x9A,0x00,0x9A,0x00,0x50, // 203
0x02,0x00,0xF8,0x01, // 204
0x00,0x00,0xFA,0x01, // 205
0x02,0x00,0xFA,0x01, // 206
0x02,0x00,0xFA,0x01, // 207
0xA4,0x00,0xFC,0x00,0xA4,0x00,0x84,0x00,0x48,0x00,0x38, // 208
0x00,0x00,0xF8,0x01,0x1E,0x00,0x06,0x00,0xC6,0x01,0x3E, // 209
0x78,0x00,0x8C,0x00,0x84,0x00,0x86,0x00,0xCC,0x00,0x78, // 210
0x78,0x00,0x8C,0x00,0x84,0x00,0x86,0x00,0xCC,0x00,0x78, // 211
0x78,0x00,0x8C,0x00,0x86,0x00,0x84,0x00,0xCC,0x00,0x78, // 212
0x78,0x00,0x8C,0x00,0x86,0x00,0x86,0x00,0xCE,0x00,0x7A, // 213
0x78,0x00,0x8C,0x00,0x86,0x00,0x86,0x00,0xCC,0x00,0x78, // 214
0x50,0x00,0x20,0x00,0x50, // 215
0xF0,0x01,0x18,0x01,0xC8,0x00,0xB8,0x00,0x8C,0x00,0x70, // 216
0x00,0x00,0x78,0x00,0x82,0x00,0x80,0x00,0x78, // 217
0x00,0x00,0x78,0x00,0x80,0x00,0x82,0x00,0x78, // 218
0x00,0x00,0x78,0x00,0x82,0x00,0x82,0x00,0x78, // 219
0x00,0x00,0x78,0x00,0x82,0x00,0x82,0x00,0x78, // 220
0x00,0x00,0xF0,0x00,0x88,0x0E,0x42,0x09,0xF8,0x07,0x00,0x02, // 221
0x10,0x00,0x08,0x00,0xFC,0x01,0x48,0x00,0x48,0x00,0x30, // 222
0x00,0x00,0x78,0x00,0xA4,0x01,0x3C,0x01,0xC0, // 223
0x60,0x00,0x90,0x00,0x94,0x00,0x90,0x00,0xF0, // 224
0x60,0x00,0x90,0x00,0x90,0x00,0x94,0x00,0xF0, // 225
0x60,0x00,0x94,0x00,0x94,0x00,0x90,0x00,0xF0, // 226
0x60,0x00,0x98,0x00,0x98,0x00,0x98,0x00,0xF8, // 227
0x60,0x00,0x98,0x00,0x98,0x00,0x90,0x00,0xF0, // 228
0x60,0x00,0x98,0x00,0x98,0x00,0x90,0x00,0xF0, // 229
0x60,0x00,0x90,0x00,0x90,0x00,0x90,0x00,0xE0,0x00,0xD0,0x00,0xD0,0x00,0x70, // 230
0x60,0x00,0x90,0x03,0x90,0x03,0x60, // 231
0x60,0x00,0xD0,0x00,0xD8,0x00,0x70, // 232
0x60,0x00,0xD0,0x00,0xD0,0x00,0x78, // 233
0x60,0x00,0xD0,0x00,0xD4,0x00,0x74, // 234
0x60,0x00,0xD8,0x00,0xD8,0x00,0x70, // 235
0x08,0x00,0x70, // 236
0x00,0x00,0x74, // 237
0x08,0x00,0x70, // 238
0x08,0x00,0x78, // 239
0xD0,0x01,0x38,0x01,0x3C,0x01,0xE0, // 240
0xE0,0x00,0x18,0x00,0x98,0x00,0x78,0x00,0x08, // 241
0x60,0x00,0x90,0x00,0x94,0x00,0x90,0x00,0x60, // 242
0x60,0x00,0x90,0x00,0x90,0x00,0x94,0x00,0x60, // 243
0x60,0x00,0x90,0x00,0x94,0x00,0x94,0x00,0x60, // 244
0x60,0x00,0x90,0x00,0x98,0x00,0x98,0x00,0x68, // 245
0x60,0x00,0x98,0x00,0x98,0x00,0x90,0x00,0x60, // 246
0x40,0x00,0x40,0x00,0x50,0x01,0x40, // 247
0xE0,0x00,0xB0,0x00,0xD0,0x00,0xB0,0x00,0x70, // 248
0x70,0x00,0x80,0x00,0x88,0x00,0x70, // 249
0x70,0x00,0x80,0x00,0x80,0x00,0x78, // 250
0x70,0x00,0x88,0x00,0x88,0x00,0x70, // 251
0x70,0x00,0x88,0x00,0x88,0x00,0x70, // 252
0x70,0x00,0x40,0x0F,0xA0,0x08,0xF4,0x07,0x80,0x01, // 253
0xCC,0x03,0xF0,0x03,0x90,0x00,0x90,0x00,0x90,0x00,0x60, // 254
0x70,0x00,0x48,0x0F,0xA8,0x08,0xF0,0x07,0x80,0x01 // 255
};
#endif /* FONT_H_ */

403
firmware/display/main.c Normal file
View File

@ -0,0 +1,403 @@
/*
* DisplayBoardFirmware.c
*
* Created: 08.01.2019 19:46:33
* Author : julian
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stddef.h> // for size_t
#define DISPLAY_PORT PORTA
#define DISPLAY_PIN PINA
#define DISPLAY_DDR DDRA
#define DISPLAY_SCL (1<<PA3)
#define DISPLAY_SDA (1<<PA2)
#define DISPLAY_SET(pin) do { DISPLAY_PORT &= ~(pin); DISPLAY_DDR |= (pin); } while(0)
#define DISPLAY_PIN_CLEAR(pin) do { DISPLAY_DDR &= ~(pin); DISPLAY_PORT |= (pin); } while(0)
#define DISPLAY_HALFCLK 1
// display commands
enum {
DISPLAY_CMD_CLK_DIV = 0xD5,
DISPLAY_CMD_MULTIPLEX = 0xA8,
DISPLAY_CMD_CHARGEPUMP = 0x8D,
DISPLAY_CMD_COMM_VOLTAGE_DETECT = 0xDB,
DISPLAY_CMD_LINE_OFFSET = 0xD3,
DISPLAY_CMD_LINE_START = 0x40,
DISPLAY_CMD_ENABLE = 0xAE,
DISPLAY_CMD_INVERT = 0xA6,
DISPLAY_CMD_TEST = 0xA4,
DISPLAY_CMD_CONTRAST = 0x81,
DISPLAY_CMD_ADDR_MODE = 0x20,
DISPLAY_CMD_COLUMN_ADDR = 0x21,
DISPLAY_CMD_PAGE_ADDR = 0x22,
DISPLAY_CMD_SCANMODE_POS = 0xC8,
DISPLAY_CMD_SCANMODE_NEG = 0xC0,
};
/* Display driver */
typedef struct {
volatile uint8_t current_buffer:1;
} display_t;
display_t display;
static inline void display_start() {
DISPLAY_SET(DISPLAY_SDA);
_delay_us(DISPLAY_HALFCLK);
DISPLAY_SET(DISPLAY_SCL);
}
static inline void display_stop() {
DISPLAY_PIN_CLEAR(DISPLAY_SCL);
_delay_us(DISPLAY_HALFCLK);
DISPLAY_PIN_CLEAR(DISPLAY_SDA);
}
const uint8_t display_addr = 0x78;
//const uint8_t display_addr = 0x1E;
// returns 1 on NACK
int display_send(uint8_t b) {
int i = 0;
while(i < 8)
{
if (b&(0x80>>i))
DISPLAY_PIN_CLEAR(DISPLAY_SDA);
else
DISPLAY_SET(DISPLAY_SDA);
_delay_us(1);
DISPLAY_PIN_CLEAR(DISPLAY_SCL);
_delay_us(DISPLAY_HALFCLK);
DISPLAY_SET(DISPLAY_SCL);
_delay_us(DISPLAY_HALFCLK-2);
i++;
}
DISPLAY_PIN_CLEAR(DISPLAY_SDA);
_delay_us(DISPLAY_HALFCLK);
DISPLAY_PIN_CLEAR(DISPLAY_SCL);
_delay_us(DISPLAY_HALFCLK);
// look for ACK
int result = DISPLAY_PIN & DISPLAY_SDA;
DISPLAY_SET(DISPLAY_SCL);
// ack means 0 during clk period
return result != 0;
}
int display_ncmd(uint8_t *cmd, uint8_t len) {
int result = 1;
display_start();
if (display_send(display_addr)) goto fail;
uint8_t prefix = 0x80;
while(len--)
{
if (display_send(prefix) || display_send(*cmd))
goto fail;
if (len-1) {
prefix = 0x00;
}
++cmd;
}
result = 0;
fail:
display_stop();
return result;
}
int display_cmd(uint8_t cmd) {
return display_ncmd(&cmd, 1);
}
int display_data_chunk(uint8_t ** data, size_t *len) {
int result = 1;
uint8_t count = 16;
display_start();
if (display_send(display_addr)) {
goto fail;
}
if (display_send(0x40))
goto fail;
while(count && *len && !display_send(**data)) {
count--;
(*len)--;
(*data)++;
}
result = 0;
fail:
display_stop();
return result;
}
int display_data(uint8_t * data, size_t len) {
int result = 1;
while(len && !(result = display_data_chunk(&data, &len))) {}
return result;
}
void display_copy(int x, int y, int w, int h, uint8_t *data, size_t len) {
display_cmd(DISPLAY_CMD_COLUMN_ADDR);
display_cmd(y);
display_cmd(y + h);
display_cmd(DISPLAY_CMD_PAGE_ADDR);
display_cmd(x + 4*display.current_buffer);
display_cmd(x + w + 4*display.current_buffer -1);
display_data(data, len);
}
void display_clear() {
static uint8_t chunk[8] = {0xFF};
size_t len = 0;
size_t c = 8;
display_cmd(DISPLAY_CMD_COLUMN_ADDR);
display_cmd(0);
display_cmd(127);
display_cmd(DISPLAY_CMD_PAGE_ADDR);
display_cmd(display.current_buffer*4);
display_cmd(display.current_buffer*4+3);
uint8_t * current = chunk;
while(len < 128*4) {
display_start();
display_send(display_addr);
display_send(0x40);
for (uint8_t i = 0; i < 16; i++) {
display_send(0x00);
}
display_stop();
len += 16;
}
}
#include "font.h"
static inline void pgm_memcpy(uint8_t * dest, const uint8_t * src, size_t s) {
while(s--) {
*dest = pgm_read_byte(src);
++src;
++dest;
}
}
void display_font_copy(char c, int x, int y) {
static uint8_t buffer[FONT_HEIGHT*2];
if (c < FONT_START || c > FONT_START + FONT_END)
return;
int offset = c - FONT_START;
uint16_t index = pgm_read_word(Fonttable + offset);
uint8_t w = pgm_read_byte(Fonttable + offset +2);
uint8_t h = pgm_read_byte(Fonttable + offset +3);
const uint8_t * current = Fonttable + index + FONT_END;
uint8_t linebuffer = pgm_read_byte(current++);
uint8_t count = 8;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
count--;
if (!count) {
count = 8;
linebuffer = pgm_read_byte(current++);
}
}
}
// pgm_memcpy((uint8_t*)&glyph_buffer, (const uint8_t*)Glyphtable, sizeof(glyph_buffer));
// pgm_memcpy(buffer, Fonttable + glyph_buffer.index, glyph_buffer.w);
// display_copy(x, y, 1, FONT_HEIGHT, buffer, FONT_HEIGHT);
}
// initializes display
// setup parameters for normal operation
void display_init()
{
display.current_buffer = 1;
DISPLAY_PIN_CLEAR(DISPLAY_SCL | DISPLAY_SDA);
display_cmd(DISPLAY_CMD_ENABLE);
display_cmd(DISPLAY_CMD_CLK_DIV);
display_cmd(0x80);
display_cmd(DISPLAY_CMD_MULTIPLEX);
display_cmd(63);
display_cmd(DISPLAY_CMD_CHARGEPUMP);
display_cmd(0x14);
display_cmd(0xDA);
display_cmd(0x02);
display_cmd(DISPLAY_CMD_LINE_OFFSET);
display_cmd(0);
display_cmd(DISPLAY_CMD_LINE_START | 0);
display_cmd(DISPLAY_CMD_COMM_VOLTAGE_DETECT);
display_cmd(0x40);
display_cmd(DISPLAY_CMD_ADDR_MODE);
display_cmd(0x01);
display_cmd(DISPLAY_CMD_SCANMODE_POS);
display_cmd(DISPLAY_CMD_TEST); // no testing mode
display_clear();
display_cmd(DISPLAY_CMD_ENABLE|1);
}
void display_swap() {
display.current_buffer = !display.current_buffer;
display_cmd(DISPLAY_CMD_LINE_START | 32*display.current_buffer);
}
// TODO: find out what display is capable of
void display_write(const char * str)
{
}
// should be called after every change to display content is made
// TODO: check if this is possible to implement
void display_present() {
}
/* encoder driver */
typedef enum {
ENC_DIR_NONE,
ENC_DIR_CW,
ENC_DIR_CCW,
} encoder_dir_t;
struct encoder;
typedef void (*encoder_callback_t)(struct encoder * encoder);
typedef struct encoder {
encoder_dir_t dir;
uint16_t velo;
int16_t pos;
encoder_callback_t callback;
} encoder_t;
encoder_t encoder;
// encoder can only be at the INT0/INT1 lines
// maybe pushbutton on pinchange
void encoder_init(encoder_t * encoder) {
*encoder = (encoder_t){};
// TODO: configure PCINT0 interrupt for direction
// TODO: configure PCINT1 interrupt for push button
}
volatile encoder_dir_t first;
#include <avr/interrupt.h>
// turning interrupt
ISR(PCINT0_vect) {
// find edge type
if (first == ENC_DIR_NONE) {
first = ENC_DIR_CCW;
return;
}
encoder.dir = first;
encoder.pos -= 1;
if (encoder.callback)
encoder.callback(&encoder);
first = ENC_DIR_NONE;
}
// push interrupt
ISR(PCINT1_vect) {
// TODO
}
/* main application */
typedef struct menuitem {
struct menuitem * root;
const char * text;
struct menuitem * children;
uint8_t children_count;
} menuitem;
#include <stddef.h>
menuitem root = {.root = NULL,
.text = NULL,
};
int main(void)
{
//_delay_ms(100);
display_init();
uint8_t face[8] = {
0b11111111,
0b11111110,
0b11111100,
0b11111000,
0b11110000,
0b11100000,
0b11000000,
0b10000000,
};
for (int j = 0; j< 16; j++)
for (int i = 0; i<4; i++)
{
display_copy(i,j*8, 1,8, face, 8);
display_font_copy('a', i,j*8);
}
display_swap();
/* Replace with your application code */
while (1)
{
}
}

Binary file not shown.

View File

@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.0.0)
set(AVR_MCU attiny84)
include(avr-toolchain.cmake)
project(slider_firmware C)
add_subdirectory(../../libs/common ${CMAKE_CURRENT_BINARY_DIR}/libs EXCLUDE_FROM_ALL)
add_avr_executable(slider_firmware main.c)
target_link_libraries(slider_firmware DSPLAB_common)

View File

@ -0,0 +1,85 @@
# give info about target
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR avr)
# find tools
find_program(AVR_CC avr-gcc)
find_program(AVR_CXX avr-g++)
find_program(AVR_OBJCOPY avr-objcopy)
find_program(AVR_SIZE_TOOL avr-size)
# set compiler (globally)
SET(CMAKE_C_COMPILER ${AVR_CC})
SET(CMAKE_CXX_COMPILER ${AVR_CXX})
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
add_definitions(-mmcu=${AVR_MCU} -DF_CPU=8000000 --std=c99)
function(add_avr_executable EXECUTABLE_NAME)
if(NOT ARGN)
message(FATAL_ERROR "No source files given for ${EXECUTABLE_NAME}.")
endif(NOT ARGN)
# set file names
set(elf_file ${EXECUTABLE_NAME})
set(hex_file ${EXECUTABLE_NAME}.hex)
set(lst_file ${EXECUTABLE_NAME}.lst)
set(map_file ${EXECUTABLE_NAME}.map)
set(eeprom_image ${EXECUTABLE_NAME}_eeprom.hex)
# elf file
add_executable(${elf_file} EXCLUDE_FROM_ALL ${ARGN})
set_target_properties(
${elf_file}
PROPERTIES
COMPILE_FLAGS "-mmcu=${AVR_MCU}"
LINK_FLAGS "-mmcu=${AVR_MCU} -Wl,--gc-sections -mrelax -Wl,-Map,${map_file}"
)
add_custom_command(
OUTPUT ${hex_file}
COMMAND
${AVR_OBJCOPY} -j .text -j .data -O ihex ${elf_file} ${hex_file}
COMMAND
${AVR_SIZE_TOOL} ${AVR_SIZE_ARGS} ${elf_file}
DEPENDS ${elf_file}
)
add_custom_command(
OUTPUT ${lst_file}
COMMAND
${AVR_OBJDUMP} -d ${elf_file} > ${lst_file}
DEPENDS ${elf_file}
)
# eeprom
add_custom_command(
OUTPUT ${eeprom_image}
COMMAND
${AVR_OBJCOPY} -j .eeprom --set-section-flags=.eeprom=alloc,load
--change-section-lma .eeprom=0 --no-change-warnings
-O ihex ${elf_file} ${eeprom_image}
DEPENDS ${elf_file}
)
add_custom_target(
build_${EXECUTABLE_NAME}
ALL
DEPENDS ${hex_file} ${lst_file} ${eeprom_image}
)
set_target_properties(
build_${EXECUTABLE_NAME}
PROPERTIES
OUTPUT_NAME "${elf_file}"
)
# clean
get_directory_property(clean_files ADDITIONAL_MAKE_CLEAN_FILES)
set_directory_properties(
PROPERTIES
ADDITIONAL_MAKE_CLEAN_FILES "${map_file}"
)
endfunction(add_avr_executable)

50482
firmware/slider/doc8183.pdf Normal file

File diff suppressed because one or more lines are too long

154
firmware/slider/main.c Normal file
View File

@ -0,0 +1,154 @@
#include <avr/io.h>
#include <avr/interrupt.h>
/* adc driver */
void adc_init() {
ADMUX = 0; // set channel, set reference to vdd
ADCSRA = (1<<ADEN) | // enable adc
(1<<ADIE); // enable adc interrupt
}
void adc_start() {}
enum {
ADC_CHANNEL_1,
ADC_CHANNEL_2,
ADC_CHANNEL_3,
ADC_CHANNEL_4,
ADC_CHANNEL_5,
ADC_CHANNEL_6,
ADC_CHANNEL_7,
ADC_CHANNEL_COUNT
};
uint16_t adc_samples[ADC_CHANNEL_COUNT];
uint8_t adc_current_sample;
ISR(ADC_vect) {
uint16_t sample;
adc_samples[adc_current_sample] = sample;
adc_current_sample = (adc_current_sample+1)/ADC_CHANNEL_COUNT;
}
/* led driver */
#define LED_DDR DDRA
#define LED_REG PORTA
#define LED_PIN 1
static inline void led_toggle() {
LED_REG ^= (1<<LED_PIN);
}
static inline void led_off() {
LED_REG &= ~(1<<LED_PIN);
}
static inline void led_on() {
LED_REG |= (1<<LED_PIN);
}
void led_init() {
LED_DDR |= (1<<LED_PIN);
led_off();
}
/* button driver */
// TODO: make interrupt driven
#define BUTTON_DDR DDRA
#define BUTTON_REG PINA
#define BUTTON_PIN 1
enum {
BUTTON_RELEASED,
BUTTON_PRESSED
} button_state;
void button_init() {
led_init();
BUTTON_DDR &= ~(1<<BUTTON_PIN);
}
int button_set_state(int state) {
if (state == BUTTON_PRESSED)
led_on();
else
led_off();
button_state = state;
return state;
}
int button_is_pressed() {
return BUTTON_REG&(1<<BUTTON_PIN);
}
/* Communication driver */
#define SLAVE_ENABLE_DDR DDRA
#define SLAVE_ENABLE_REG PINA
#define SLAVE_ENABLE_PIN 1
#include <common/interface.h>
void comm_write(iface_t * iface, byte_t byte) {
// disable interrupt
uint8_t temp = USICR;
USICR &= ~(1<<USIOIE);
// write data register
USIDR = byte;
// wait for buffer overflow
while(!(USICR&(1<<USIOIE))) {}
// restore control register
USICR = temp;
}
iface_t comm_iface;
void comm_init() {
// TODO: setup pins
// TODO: setup USART in synchronous mode
USICR = (1<<USIWM0)|(1<<USICS1);
comm_iface.write = comm_write;
}
void comm_start() {
// TODO: activate USART
USICR |= (1<<USIOIE);
}
ISR(USI_OVF_vect) {
byte_t byte = USIBR;
// only operate when enabled
if (SLAVE_ENABLE_REG & (1<<SLAVE_ENABLE_PIN)) {
return;
}
if (comm_iface.on_read) {
comm_iface.on_read(&comm_iface, byte, comm_iface.callback_data);
}
}
/* main application code */
void init() {
adc_init();
button_init();
comm_init();
adc_start();
comm_start();
// activate interrupts
sei();
}
int main() {
init();
while(1) {}
}