diff options
author | Daniel Friesel <derf@finalrewind.org> | 2021-04-12 22:33:31 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2021-04-12 22:33:31 +0200 |
commit | b650f2ac498df4ba18d23ad7f02637f40917c28e (patch) | |
tree | f5c44e669295988a7c626a6be7df6003a5f0b918 | |
parent | de46e19c47842dc3e2050b0c7e948b9884e9a1f5 (diff) |
add ssd1306 test app
-rw-r--r-- | src/app/ssd1306test/Kconfig | 6 | ||||
-rw-r--r-- | src/app/ssd1306test/Makefile.inc | 13 | ||||
-rw-r--r-- | src/app/ssd1306test/main.cc | 41 | ||||
-rwxr-xr-x | src/app/ssd1306test/png-to-h | 23 | ||||
-rw-r--r-- | src/driver/ssd1306.cc | 3 | ||||
-rwxr-xr-x | tests/build-arduino-nano | 2 | ||||
-rwxr-xr-x | tests/build-msp430fr5969lp | 2 | ||||
-rwxr-xr-x | tests/build-msp430fr5994lp | 2 |
8 files changed, 89 insertions, 3 deletions
diff --git a/src/app/ssd1306test/Kconfig b/src/app/ssd1306test/Kconfig new file mode 100644 index 0000000..dd71bba --- /dev/null +++ b/src/app/ssd1306test/Kconfig @@ -0,0 +1,6 @@ +# Copyright 2021 Daniel Friesel +# +# SPDX-License-Identifier: CC0-1.0 + +prompt "SSD1306 Test" +depends on driver_ssd1306 && loop && !wakeup diff --git a/src/app/ssd1306test/Makefile.inc b/src/app/ssd1306test/Makefile.inc new file mode 100644 index 0000000..9a32d56 --- /dev/null +++ b/src/app/ssd1306test/Makefile.inc @@ -0,0 +1,13 @@ +# vim:ft=make +# +# Copyright 2021 Daniel Friesel +# +# SPDX-License-Identifier: CC0-1.0 + +ifdef app + CONFIG_loop = y + override arch_drivers += ,i2c + CONFIG_driver_ssd1306 = y + CONFIG_driver_ssd1306_width = 128 + CONFIG_driver_ssd1306_height = 64 +endif diff --git a/src/app/ssd1306test/main.cc b/src/app/ssd1306test/main.cc new file mode 100644 index 0000000..909d26d --- /dev/null +++ b/src/app/ssd1306test/main.cc @@ -0,0 +1,41 @@ +/* + * Copyright 2021 Daniel Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#include "arch.h" +#include "driver/gpio.h" +#include "driver/stdout.h" +#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C) +#include "driver/i2c.h" +#else +#include "driver/soft_i2c.h" +#endif +#include "driver/ssd1306.h" + +unsigned char const image[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 192, 224, 240, 240, 240, 248, 248, 248, 248, 248, 248, 248, 248, 248, 240, 240, 240, 224, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 184, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 254, 254, 254, 255, 255, 255, 124, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 30, 63, 63, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 223, 3, 255, 255, 255, 255, 255, 246, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 7, 15, 31, 15, 15, 143, 255, 255, 255, 255, 255, 239, 159, 31, 31, 15, 7, 3, 3, 0, 0, 15, 127, 255, 255, 255, 127, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 192, 224, 240, 248, 252, 254, 135, 7, 7, 6, 142, 236, 252, 248, 152, 16, 48, 96, 96, 192, 192, 128, 128, 128, 128, 128, 128, 128, 128, 128, 192, 192, 128, 128, 128, 192, 224, 248, 252, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 252, 248, 240, 224, 128, 128, 128, 129, 193, 129, 128, 128, 128, 128, 128, 128, 128, 128, 128, 192, 192, 96, 32, 48, 16, 216, 248, 252, 204, 142, 6, 7, 7, 142, 254, 252, 248, 240, 224, 192, 128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 243, 1, 1, 14, 255, 255, 255, 31, 6, 0, 0, 63, 255, 255, 63, 7, 0, 0, 0, 248, 254, 255, 255, 125, 1, 1, 1, 49, 253, 255, 255, 253, 1, 1, 19, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 191, 1, 1, 33, 253, 255, 255, 253, 49, 1, 1, 1, 125, 255, 255, 252, 248, 0, 0, 0, 7, 63, 255, 255, 63, 0, 0, 6, 31, 255, 255, 255, 30, 1, 1, 243, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 3, 7, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 31, 31, 3, 0, 0, 0, 0, 0, 3, 63, 191, 129, 192, 224, 254, 255, 255, 255, 63, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 255, 224, 224, 192, 131, 191, 127, 7, 0, 0, 0, 0, 0, 3, 63, 63, 0, 0, 0, 0, 0, 0, 1, 7, 0, 0, 0, 0, 0, 0, 7, 15, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 160, 240, 240, 240, 240, 224, 224, 240, 248, 248, 124, 62, 63, 31, 31, 15, 7, 7, 3, 1, 0, 192, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 254, 192, 0, 1, 3, 7, 7, 15, 31, 31, 63, 62, 124, 124, 248, 240, 248, 248, 248, 240, 176, 176, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +void loop(void) +{ + static unsigned char i = 0; + gpio.led_toggle(1); + ssd1306.setInvert((i % 20) >= 10); + ssd1306.setContrast((i % 10) * 25); + + i++; +} + +int main(void) +{ + arch.setup(); + gpio.setup(); + kout.setup(); + i2c.setup(); + ssd1306.init(); + + ssd1306.showImage((unsigned char*)image, sizeof(image)); + + arch.idle_loop(); + + return 0; +} diff --git a/src/app/ssd1306test/png-to-h b/src/app/ssd1306test/png-to-h new file mode 100755 index 0000000..5e95967 --- /dev/null +++ b/src/app/ssd1306test/png-to-h @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +from PIL import Image +import sys + + +def load_image(filename): + im = Image.open(filename) + w, h = im.size + buf = [0 for i in range(buf_w * buf_h // 8)] + for y in range(min(h, buf_h)): + for x in range(min(w, buf_w)): + if im.getpixel((x, y)): + buf[(y // 8) * buf_w + x] |= 1 << (y % 8) + return buf + + +buf_w = int(sys.argv[1]) +buf_h = int(sys.argv[2]) +filename = sys.argv[3] + +buf = load_image(filename) +print(", ".join(map(str, buf))) diff --git a/src/driver/ssd1306.cc b/src/driver/ssd1306.cc index cf36c13..1d4e1f3 100644 --- a/src/driver/ssd1306.cc +++ b/src/driver/ssd1306.cc @@ -4,8 +4,11 @@ * SPDX-License-Identifier: BSD-2-Clause */ #include "driver/ssd1306.h" +#if defined(MULTIPASS_ARCH_HAS_I2C) && !defined(DRIVER_SOFTI2C) #include "driver/i2c.h" +#else #include "driver/soft_i2c.h" +#endif void SSD1306::writeCommand(uint8_t command) { diff --git a/tests/build-arduino-nano b/tests/build-arduino-nano index 20185e0..f57434b 100755 --- a/tests/build-arduino-nano +++ b/tests/build-arduino-nano @@ -4,7 +4,7 @@ set -e apps="bme680-max44009-logger button-and-motion-logger donothing i2cdetect ledblink mpu9250_motionlog - shell sysinfo timertest + shell ssd1306test sysinfo timertest waittest wetterstation ws2812b_dmap ws2812b_uart" for app in $apps; do diff --git a/tests/build-msp430fr5969lp b/tests/build-msp430fr5969lp index 3971237..c23a882 100755 --- a/tests/build-msp430fr5969lp +++ b/tests/build-msp430fr5969lp @@ -4,7 +4,7 @@ set -e apps="bme680-max44009-logger countertest donothing i2cdetect ledblink - nrf24l01test sharp96test shell sysinfo timertest + nrf24l01test ssd1306test sharp96test shell sysinfo timertest waittest" for app in $apps; do diff --git a/tests/build-msp430fr5994lp b/tests/build-msp430fr5994lp index 7db2e32..7b2a4bf 100755 --- a/tests/build-msp430fr5994lp +++ b/tests/build-msp430fr5994lp @@ -4,7 +4,7 @@ set -e apps="bme680-max44009-logger countertest deflatetest donothing i2cdetect ledblink - nrf24l01test sharp96-bad-apple sharp96test shell sysinfo timertest + nrf24l01test ssd1306test sharp96-bad-apple sharp96test shell sysinfo timertest waittest" for app in $apps; do |