diff options
| author | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-04-09 18:25:15 +0200 |
|---|---|---|
| committer | Glenn Ruben Bakke <glennbakke@gmail.com> | 2017-04-09 18:25:15 +0200 |
| commit | 4dd86178bc7981ca8b8cf4548c61733125f0ff1a (patch) | |
| tree | 3b414613c4dda48988c9a21e41b83555302727be | |
| parent | a026d3475f4d0d06a1d32496fa7f52194eaf18dc (diff) | |
nrf5: Removing custom display, framebuffer and graphics module to make branch contain core components instead of playground modules.
38 files changed, 0 insertions, 5938 deletions
diff --git a/nrf5/Makefile b/nrf5/Makefile index 976c5d7a2..511fe4c46 100644 --- a/nrf5/Makefile +++ b/nrf5/Makefile @@ -137,21 +137,6 @@ SRC_C += \ fatfs_port.c \ DRIVERS_SRC_C += $(addprefix modules/,\ - display/moddisplay.c \ - display/epaper_sld00200p_obj.c \ - display/epaper_sld00200p_driver.c \ - display/lcd_ili9341_obj.c \ - display/lcd_ili9341_driver.c \ - display/lcd_ls0xxb7dxxx_obj.c \ - display/lcd_ls0xxb7dxxx_driver.c \ - display/lcd_ssd1289_obj.c \ - display/lcd_ssd1289_driver.c \ - display/oled_ssd1305_obj.c \ - display/oled_ssd1305_driver.c \ - display/oled_ssd1306_obj.c \ - display/oled_ssd1306_driver.c \ - display/framebuffer.c \ - graphic/draw.c \ machine/modmachine.c \ machine/uart.c \ machine/spi.c \ diff --git a/nrf5/boards/pca10028/mpconfigboard.h b/nrf5/boards/pca10028/mpconfigboard.h index ae8c9e835..8dc210c41 100644 --- a/nrf5/boards/pca10028/mpconfigboard.h +++ b/nrf5/boards/pca10028/mpconfigboard.h @@ -30,13 +30,6 @@ #define MICROPY_HW_MCU_NAME "NRF51822" #define MICROPY_PY_SYS_PLATFORM "nrf51-DK" -#define MICROPY_PY_DISPLAY (0) -#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (0) -#define MICROPY_PY_DISPLAY_LCD_ILI9341 (0) -#define MICROPY_PY_DISPLAY_LCD_SSD1289 (0) -#define MICROPY_PY_DISPLAY_OLED_SSD1305 (0) -#define MICROPY_PY_DISPLAY_OLED_SSD1306 (0) - #define MICROPY_PY_MACHINE_HW_SPI (1) #define MICROPY_PY_MACHINE_TIMER (1) #define MICROPY_PY_MACHINE_RTC (1) diff --git a/nrf5/boards/pca10040/mpconfigboard.h b/nrf5/boards/pca10040/mpconfigboard.h index 12f0cb5d3..50b3da7fc 100644 --- a/nrf5/boards/pca10040/mpconfigboard.h +++ b/nrf5/boards/pca10040/mpconfigboard.h @@ -38,12 +38,6 @@ #define MICROPY_PY_MACHINE_ADC (1) #define MICROPY_PY_MACHINE_TEMP (1) -#define MICROPY_PY_DISPLAY (1) -#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (1) -#define MICROPY_PY_DISPLAY_LCD_ILI9341 (1) -#define MICROPY_PY_DISPLAY_LCD_SSD1289 (1) -#define MICROPY_PY_DISPLAY_OLED_SSD1306 (1) - #define MICROPY_HW_HAS_SWITCH (0) #define MICROPY_HW_HAS_FLASH (0) #define MICROPY_HW_HAS_SDCARD (0) diff --git a/nrf5/boards/pca10056/mpconfigboard.h b/nrf5/boards/pca10056/mpconfigboard.h index a4673057f..f111e737d 100644 --- a/nrf5/boards/pca10056/mpconfigboard.h +++ b/nrf5/boards/pca10056/mpconfigboard.h @@ -36,14 +36,6 @@ #define MICROPY_PY_MACHINE_ADC (1) #define MICROPY_PY_MACHINE_TEMP (1) -#define MICROPY_PY_DISPLAY (1) -#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (1) -#define MICROPY_PY_DISPLAY_LCD_ILI9341 (1) -#define MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX (1) -#define MICROPY_PY_DISPLAY_LCD_SSD1289 (1) -#define MICROPY_PY_DISPLAY_OLED_SSD1305 (1) -#define MICROPY_PY_DISPLAY_OLED_SSD1306 (1) - #define MICROPY_HW_HAS_SWITCH (0) #define MICROPY_HW_HAS_FLASH (0) #define MICROPY_HW_HAS_SDCARD (0) diff --git a/nrf5/examples/epaper.py b/nrf5/examples/epaper.py deleted file mode 100644 index 743ae2e0c..000000000 --- a/nrf5/examples/epaper.py +++ /dev/null @@ -1,451 +0,0 @@ -# This file is part of the Micro Python project, http://micropython.org/ -# -# The MIT License (MIT) -# -# Copyright (c) 2017 Glenn Ruben Bakke -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -""" -E-paper EM027AS011. - -Pin layout on pca10040 (nrf52): - -EPAPER_PANEL_ON 13 (Arduino D2) -EPAPER_BORDER 14 (Arduino D3) -EPAPER_PWM 16 (Arduino D5) -EPAPER_RESET 17 (Arduino D6) -EPAPER_BUSY 18 (Arduino D7) -EPAPER_DISCHARGE 19 (Arduino D8) -EPAPER_TEMP_SENSOR 03 (Arduino A0) -EPAPER_CS 22 (Arduino D10) -EPAPER_DIN 23 (Arduino D11) -EPAPER_DOUT 24 (Arduino D12) -EPAPER_CLK 25 (Arduino D13) - -Example usage on pca10040: - -from epaper import Epaper - -epd = Epaper() -epd.fill(0) -epd.text("Hello World!", 50, 50) -epd.show() - -epd.refresh() -epd.refresh() -""" - -import os -import time -import lcd_mono_fb - -from machine import SPI, Pin, PWM - -EPD_STATE_COMP = const(0x1) -EPD_STATE_WHITE = const(0x2) -EPD_STATE_INV = const(0x3) -EPD_STATE_NORM = const(0x4) - -class Epaper: - def __init__(self, width=264, height=176, vertical=False): - - self.width = width - self.height = height - self.vertical = vertical - self.framebuf = lcd_mono_fb.MonoFB(self.line_update, self.width, self.height, True) - - self.reset = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP) - self.panel_on = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) - self.discharge = Pin("A19", mode=Pin.OUT, pull=Pin.PULL_UP) - self.border = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) - self.busy = Pin("A18", mode=Pin.IN, pull=Pin.PULL_DISABLED) - self.cs = Pin("A22", mode=Pin.OUT, pull=Pin.PULL_UP) - - self.reset.low() - self.panel_on.low() - self.discharge.low() - self.border.low() - - self.pwm = PWM(0, Pin("A16", mode=Pin.OUT), freq=PWM.FREQ_250KHZ, duty=50, period=2) - - # Min baudrate 4M, max 12M - self.spi = SPI(0, baudrate=80000000) - # self.spi.init(baudrate=8000000, phase=0, polarity=0) - - def line_update(self, o, line, new_bytes, old_bytes): - if new_bytes: - self._update_line(line, old_bytes, EPD_STATE_COMP) - self._update_line(line, old_bytes, EPD_STATE_WHITE) - self._update_line(line, new_bytes, EPD_STATE_INV) - self._update_line(line, new_bytes, EPD_STATE_NORM) - else: - self._update_line(line, old_bytes, EPD_STATE_NORM) - - def clear(self): - line_count = self.height; - for i in range(0, line_count): - self._update_line(i, None, EPD_STATE_COMP, 0xFF) - - time.sleep_ms(500) - - for i in range(0, line_count): - self._update_line(i, None, EPD_STATE_WHITE, 0xAA) - - time.sleep_ms(500) - - for i in range(0, line_count): - self._update_line(i, None, EPD_STATE_INV, 0xFF) - - time.sleep_ms(500) - - for i in range(0, line_count): - self._update_line(i, None, EPD_STATE_NORM, 0xAA) - - time.sleep_ms(500) - - def init_display(self): - - self.pwm.init() # start the pwm - - print("sleep") - time.sleep_ms(5) - print("wakeup") - self.panel_on.high() - time.sleep_ms(10) - - self.reset.high() - self.border.high() - self.cs.high() - - time.sleep_ms(5) - - self.reset.low() - - time.sleep_ms(5) - - self.reset.high() - - time.sleep_ms(5) - print("Wait for busy") - self.wait_for_busy_release() - - time.sleep_us(10) - # channel select - self.write_data(bytearray([0x70, 0x01])) - time.sleep_us(10) - - # CS - self.write_data(bytearray([0x72, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00])) - - # DC/DC frequency - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x06])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0xff])) - - # high power mode osc - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x07])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x9d])) - - # disable ADC - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x08])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x00])) - - # Vcom level - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x09])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0xd0, 0x00])) - - # gate and source voltage levels - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x04])) - - # GS - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x00])) - - time.sleep_ms(5) - - # driver latch on - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x03])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x01])) - - # driver latch off - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x03])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x00])) - - time.sleep_ms(5) - - # charge pump positive voltage on - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x05])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x01])) - - # final delay before PWM off - time.sleep_us(30) - - # stop PWM - self.pwm.deinit() - - # charge pump negative voltage on - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x05])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x03])) - - time.sleep_us(30) - - # Vcom driver on - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x05])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x0f])) - - time.sleep_ms(30); - - # output enable to disable - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x02])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x24])) - - def wait_for_busy_release(self): - # wait for COG to become ready - while (self.busy.value() == 1): - pass - - def _update_line(self, line, data, state, fixed=None): - time.sleep_us(10) - - self.write_data(bytearray([0x70, 0x04])) - time.sleep_us(10) - - # gate source - self.write_data(bytearray([0x72, 0x00])) - time.sleep_us(10) - - self.write_data(bytearray([0x70, 0x0a])) - time.sleep_us(10) - - self.cs.low() - - self.write_data_wait(bytearray([0x72])) - - bytes_per_line = self.width // 8; - - # even pixels - if data: - for i in range(bytes_per_line - 1, -1, -1): - - pixels = data[i] & 0xaa; - - if state == EPD_STATE_COMP: - # B -> W, W -> B (current image) - pixels = 0xaa | ((pixels ^ 0xaa) >> 1) - - elif state == EPD_STATE_WHITE: - # B -> N, W -> W (current image) - pixels = 0x55 + ((pixels ^ 0xaa) >> 1) - - elif state == EPD_STATE_INV: - # B -> N, W -> B (new image) - pixels = 0x55 | (pixels ^ 0xaa) - - elif state == EPD_STATE_NORM: - # B -> B, W -> W (new image) - pixels = 0xaa | (pixels >> 1) - - self.write_data_wait(bytearray([pixels])); - else: - self.write_data_wait(bytearray([fixed] * bytes_per_line)); - - bytes_per_scan = 176 // 4; - # scan line - for i in range(0, bytes_per_scan): - if (line // 4 == i): - self.write_data_wait(bytearray([0xc0 >> (2 * (line & 0x03))])) - else: - self.write_data_wait(bytearray([0x00])) - - # odd pixels - if data: - for i in range (0, bytes_per_line): - pixels = data[i] & 0x55 - - if state == EPD_STATE_COMP: - pixels = 0xaa | (pixels ^ 0x55) - - elif state == EPD_STATE_WHITE: - pixels = 0x55 + (pixels ^ 0x55) - - elif state == EPD_STATE_INV: - pixels = 0x55 | ((pixels ^ 0x55) << 1) - - elif state == EPD_STATE_NORM: - pixels = 0xaa | pixels - - p1 = (pixels >> 6) & 0x03; - p2 = (pixels >> 4) & 0x03; - p3 = (pixels >> 2) & 0x03; - p4 = (pixels >> 0) & 0x03; - - pixels = (p1 << 0) | (p2 << 2) | (p3 << 4) | (p4 << 6); - - self.write_data_wait(bytearray([pixels])) - else: - self.write_data_wait(bytearray([fixed] * bytes_per_line)) - - # Complete line - self.write_data_wait(bytearray([0x00])) - - self.cs.high() - - time.sleep_us(10) - - - self.write_data(bytearray([0x70, 0x02])) - time.sleep_us(10) - - self.write_data(bytearray([0x72, 0x2f])) - - def deinit_display(self): - # all display sizes - self._update_line(0x7fff, None, EPD_STATE_NORM, 0x55) - time.sleep_ms(25) - self.border.low() - time.sleep_ms(250) - self.border.high() - - # latch reset turn on - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x03])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x01])) - - # output enable off - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x02])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x05])) - - # Vcom power off - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x05])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x0e])) - - # power off negative charge pump - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x05])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x02])) - - # discharge - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x04])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x0c])) - time.sleep_us(120) - - # all charge pumps off - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x05])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x00])) - - # turn of osc - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x07])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x0d])) - - # discharge internal - 1 - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x04])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x50])) - time.sleep_us(40) - - # discharge internal - 2 - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x04])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0xA0])) - time.sleep_us(40) - - # discharge internal - 3 - time.sleep_us(10) - self.write_data(bytearray([0x70, 0x04])) - time.sleep_us(10) - self.write_data(bytearray([0x72, 0x00])) - - # turn of power and all signals - time.sleep_ms(10) - self.reset.low() - self.panel_on.low() - self.border.low() - - # discharge pulse - self.discharge.high() - time.sleep_us(250) - self.discharge.low() - - self.cs.high() - - def show(self): - self.init_display() - self.framebuf.show() - self.deinit_display() - - def refresh(self): - self.init_display() - self.framebuf.refresh() - self.deinit_display() - - def fill(self, col): - self.framebuf.fill(col) - - def pixel(self, x, y, col): - self.framebuf.pixel(x, y, col) - - def scroll(self, dx, dy): - self.framebuf.scroll(dx, dy) - - def text(self, string, x, y, col=1): - self.framebuf.text(string, x, y, col) - - def write_data_wait(self, buf): - self.spi.write(buf) - self.wait_for_busy_release() - - def write_data(self, buf): - self.cs.low() - self.spi.write(buf) - self.cs.high() diff --git a/nrf5/examples/game2048.py b/nrf5/examples/game2048.py deleted file mode 100644 index 3d321d92c..000000000 --- a/nrf5/examples/game2048.py +++ /dev/null @@ -1,338 +0,0 @@ -# This file is part of the Micro Python project, http://micropython.org/ -# -# The MIT License (MIT) -# -# Copyright (c) 2017 Glenn Ruben Bakke -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. - -''' -Usage: - -from game2048 import Game -g = Game() -g.start() - -''' - -from machine import ADC -from machine import Pin, SPI -from display import SSD1305 -import draw -import time - -font_128 = [ - " x xx xx", - " xx x x x x", - "x x x x x", - " x x xx", - " x x x x", - " x x x x", - " xxx xxxx xx" -] - -font_256 = [ - " xx xxxx xx", - "x x x x x", - " x xxx x ", - " x x xxxx", - " x x x x", - "x x x x", - "xxxx xxx xx" -] - -font_512 = [ - "xxxx x xx", - "x xx x x", - "xxx x x x", - " x x x", - " x x x", - " x x x", - "xxx xxx xxxx" -] - -font_1024 = [ - " xx x x x x", - "x x x x x x x x", - " x x x x x x", - " x x x x xxx", - " x x x x x", - " x x x x x", - " x x xxx x" -] - -DIR_UP = const(0x1) -DIR_DOWN = const(0x2) -DIR_LEFT = const(0x3) -DIR_RIGHT = const(0x4) -DIR_CENTER = const(0x5) - -class Game: - def __init__(self): - -# # setup harware for nrf51822 / pca10028 -# cs = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) -# reset = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -# dc = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -# spi = SPI(0, baudrate=8000000) -# self.screen = SSD1305(128, 64, spi, cs, dc, reset) -# self.x_adc = ADC(2) -# self.y_adc = ADC(3) -# self.adc_threshold = 205 - - # setup harware for nrf52840 / pca10056 - cs = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP) - reset = Pin("B2", mode=Pin.OUT, pull=Pin.PULL_UP) - dc = Pin("B1", mode=Pin.OUT, pull=Pin.PULL_UP) - spi = SPI(0, baudrate=8000000) - self.screen = SSD1305(128, 64, spi, cs, dc, reset) - self.x_adc = ADC(1) - self.y_adc = ADC(2) - self.adc_threshold = 130 - - # game setup - self.grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] - self._rand = 1337 - self.not_game_over = True - self.score = 0 - - - def move(self, dir): - if (dir == DIR_UP): - # float up - for col in range(0, 4): - for row1 in range(1, 5): - for row0 in range(1, row1): - if self.grid[col][row0 - 1] == 0: - if self.grid[col][row0]: - self.grid[col][row0 - 1] = self.grid[col][row0] - self.grid[col][row0] = 0 - # collapse - for col in range(0, 4): - for row0 in range(0, 3): - if self.grid[col][row0] == self.grid[col][row0 + 1]: - self.grid[col][row0] += self.grid[col][row0] - self.score += self.grid[col][row0] - self.grid[col][row0 + 1] = 0 - # float up - for col in range(0, 4): - for row1 in range(1, 5): - for row0 in range(1, row1): - if self.grid[col][row0 - 1] == 0: - if self.grid[col][row0]: - self.grid[col][row0 - 1] = self.grid[col][row0] - self.grid[col][row0] = 0 - elif (dir == DIR_DOWN): - # float down - for col in range(0, 4): - for row1 in range(1, 5): - for row0 in range(row1, 4): - if self.grid[col][row0] == 0: - if self.grid[col][row0 - 1]: - self.grid[col][row0] = self.grid[col][row0 - 1] - self.grid[col][row0 - 1] = 0 - # collapse - for col in range(0, 4): - for row0 in range(1, 4): - if self.grid[col][row0] == self.grid[col][row0 - 1]: - self.grid[col][row0] += self.grid[col][row0] - self.score += self.grid[col][row0] - self.grid[col][row0 - 1] = 0 - # float down - for col in range(0, 4): - for row1 in range(1, 5): - for row0 in range(row1, 4): - if self.grid[col][row0] == 0: - if self.grid[col][row0 - 1]: - self.grid[col][row0] = self.grid[col][row0 - 1] - self.grid[col][row0 - 1] = 0 - elif (dir == DIR_LEFT): - # float left - for row in range(0, 4): - for col1 in range(1, 5): - for col0 in range(1, col1): - if self.grid[col0 - 1][row] == 0: - if self.grid[col0][row]: - self.grid[col0 - 1][row] = self.grid[col0][row] - self.grid[col0][row] = 0 - # collapse - for row in range(0, 4): - for col0 in range(0, 3): - if self.grid[col0][row] == self.grid[col0 + 1][row]: - self.grid[col0][row] += self.grid[col0][row] - self.score += self.grid[col0][row] - self.grid[col0 + 1][row] = 0 - # float left - for row in range(0, 4): - for col1 in range(1, 5): - for col0 in range(1, col1): - if self.grid[col0 - 1][row] == 0: - if self.grid[col0][row]: - self.grid[col0 - 1][row] = self.grid[col0][row] - self.grid[col0][row] = 0 - elif (dir == DIR_RIGHT): - # float right - for row in range(0, 4): - for col1 in range(1, 5): - for col0 in range(col1, 4): - if self.grid[col0][row] == 0: - if self.grid[col0 - 1][row]: - self.grid[col0][row] = self.grid[col0 - 1][row] - self.grid[col0 - 1][row] = 0 - # collapse - for row in range(0, 4): - for col0 in range(1, 4): - if self.grid[col0][row] == self.grid[col0 - 1][row]: - self.grid[col0][row] += self.grid[col0][row] - self.score += self.grid[col0][row] - self.grid[col0 - 1][row] = 0 - # float right - for row in range(0, 4): - for col1 in range(1, 5): - for col0 in range(col1, 4): - if self.grid[col0][row] == 0: - if self.grid[col0 - 1][row]: - self.grid[col0][row] = self.grid[col0 - 1][row] - self.grid[col0 - 1][row] = 0 - def set_val(self, x, y, val): - self.grid[x][y] = val - def get_val(self, x, y): - return self.grid[x][y] - def draw_high_number(self, font, x, y): - for rel_y, line in enumerate(font): - for rel_x in range(0, len(line)): - if (line[rel_x] == 'x'): - self.screen.pixel(x + rel_x, y + rel_y, 1) - def draw_tile(self, x, y): - val = self.get_val(x, y) - if val != 0: - x0 = x * 16 - y0 = y * 16 - if (val < 16): - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - draw.text(self.screen, str(val), x0 + 4, y0 + 4, 1) - elif val == 16: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - draw.text(self.screen, "1", x0 + 1, y0 + 4, 1) - draw.text(self.screen, "6", x0 + 7, y0 + 4, 1) - elif val == 32: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - draw.text(self.screen, "3", x0 + 1, y0 + 4, 1) - draw.text(self.screen, "2", x0 + 7, y0 + 4, 1) - elif val == 64: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - draw.text(self.screen, "6", x0 + 1, y0 + 4, 1) - draw.text(self.screen, "4", x0 + 7, y0 + 4, 1) - elif val == 128: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - self.draw_high_number(font_128, x0 + 1, y0 + 4) - elif val == 256: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - self.draw_high_number(font_256, x0 + 1, y0 + 4) - elif val == 512: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - self.draw_high_number(font_512, x0 + 1, y0 + 4) - elif val == 1024: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - self.draw_high_number(font_1024, x0 + 1, y0 + 4) - elif val == 2048: - draw.rectangle(self.screen, x0, y0, x0 + 15, y0 + 15, 1) - self.draw_high_number(font_2048, x0 + 1, y0 + 4) - def read_stick_x(self): - return self.x_adc.value() - def read_stick_y(self): - return self.y_adc.value() - def wait_for_move(self): - x_val = self.read_stick_x() - y_val = self.read_stick_y() - if x_val > self.adc_threshold + 15: - return DIR_RIGHT - elif x_val < self.adc_threshold - 15: - return DIR_LEFT - if y_val > self.adc_threshold + 15: - return DIR_UP - elif y_val < self.adc_threshold - 15: - return DIR_DOWN - return DIR_CENTER - def get_free_tiles(self): - list = [] - for x in range(0, 4): - for y in range(0, 4): - if self.get_val(x, y) == 0: - list.append((x, y)) - return list - def draw_all_tiles(self): - for x in range(0, 4): - for y in range(0, 4): - self.draw_tile(x, y) - def rand(self, mod=0): - self._rand = ((214013*self._rand+2531011)>>16)&0x7FFF - if mod: - return self._rand % mod - else: - return self._rand - def add_random_tile(self): - free_tiles = self.get_free_tiles() - if free_tiles: - x,y = free_tiles[self.rand(len(free_tiles))] - new_val = 2 << self.rand(2) - self.set_val(x, y, new_val) - return True - else: - return False - def draw_score(self): - draw.text(self.screen, "Score:", 70, 10, 1) - draw.text(self.screen, str(self.score), 70, 20, 1) - def clear_grid(self): - # Because the the double array does not initialize correctly - # in micropython, we do an explicit clear - for i in range(0, 4): - for j in range(0, 4): - self.grid[i][j] = 0 - def start(self): - self.screen.fill(0) - draw.text(self.screen, "Touch the stick", 10, 20, 1) - draw.text(self.screen, " to start the", 10, 30, 1) - draw.text(self.screen, " game! =)", 10, 40, 1) - self.screen.show() - in_center = False - x_move = True - y_move = True - wait_for_center = False - self.clear_grid() - while self.not_game_over: - move_dir = self.wait_for_move() - if move_dir != DIR_CENTER and wait_for_center == False: - self.move(move_dir) - self.screen.fill(0) - res = self.add_random_tile() - if not res: - self.not_game_over = False - else: - self.draw_all_tiles() - self.draw_score() - self.screen.show() - wait_for_center = True - if move_dir == DIR_CENTER: - wait_for_center = False - self.screen.fill(0) - draw.text(self.screen, "Game Over!", 10, 20, 1) - draw.text(self.screen, "Score:", 10, 30, 1) - draw.text(self.screen, str(self.score), 10, 40, 1) - self.screen.show()
\ No newline at end of file diff --git a/nrf5/modules/display/epaper_sld00200p_driver.c b/nrf5/modules/display/epaper_sld00200p_driver.c deleted file mode 100644 index 30ce590ce..000000000 --- a/nrf5/modules/display/epaper_sld00200p_driver.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "epaper_sld00200p_driver.h" - -#if MICROPY_PY_DISPLAY_EPAPER_SLD00200P - -#include "py/mphal.h" - -#include "epaper_sld00200p_driver.h" -#include "hal_spi.h" -#include "hal_time.h" - -#define BYTE_ARRAY(...) ((uint8_t[]){ __VA_ARGS__}) -#define DATA_WRITE(...) (data_write_buffer(BYTE_ARRAY(__VA_ARGS__), sizeof(BYTE_ARRAY(__VA_ARGS__)))) - -static NRF_SPI_Type * mp_spi_instance; -static NRF_PWM_Type * mp_pwm_instance; -static pin_obj_t * mp_pin_cs; -static pin_obj_t * mp_pin_panel_on; -static pin_obj_t * mp_pin_border; -static pin_obj_t * mp_pin_busy; -static pin_obj_t * mp_pin_reset; -static pin_obj_t * mp_pin_discharge; - -#if 0 -static pin_obj_t * mp_pin_temp_sensor; -#endif - -static void wait_for_busy_release(void) { - while (mp_hal_pin_read(mp_pin_busy) == 1) { - ; - } -} - -static void data_write_buffer(uint8_t * p_bytes, uint16_t num_of_bytes) { - mp_hal_pin_low(mp_pin_cs); - - hal_spi_master_tx_rx(mp_spi_instance, num_of_bytes, p_bytes, NULL); - - mp_hal_pin_high(mp_pin_cs); -} - -static void raw_write(uint8_t value) -{ - hal_spi_master_tx_rx(mp_spi_instance, 1, &value, NULL); -} - -void driver_sld00200p_init(NRF_SPI_Type * p_spi_instance, - NRF_PWM_Type * p_pwm_instance, - pin_obj_t * p_pin_cs, - pin_obj_t * p_pin_panel_on, - pin_obj_t * p_pin_border, - pin_obj_t * p_pin_busy, - pin_obj_t * p_pin_reset, - pin_obj_t * p_pin_discharge) { - - mp_spi_instance = p_spi_instance; - mp_pwm_instance = p_pwm_instance; - mp_pin_cs = p_pin_cs; - mp_pin_panel_on = p_pin_panel_on; - mp_pin_border = p_pin_border; - mp_pin_busy = p_pin_busy; - mp_pin_reset = p_pin_reset; - mp_pin_discharge = p_pin_discharge; - - driver_sld00200p_reinit(); -} - -void driver_sld00200p_reinit(void) { - mp_hal_pin_low(mp_pin_reset); - mp_hal_pin_low(mp_pin_panel_on); - mp_hal_pin_low(mp_pin_discharge); - mp_hal_pin_low(mp_pin_border); - - // start the pwm - hal_pwm_start(mp_pwm_instance); - - mp_hal_delay_ms(5); - - mp_hal_pin_high(mp_pin_panel_on); - - mp_hal_delay_ms(10); - - mp_hal_pin_high(mp_pin_reset); - mp_hal_pin_high(mp_pin_border); - mp_hal_pin_high(mp_pin_cs); - - // make reset square wave - mp_hal_delay_ms(5); - mp_hal_pin_low(mp_pin_reset); - mp_hal_delay_ms(5); - mp_hal_pin_high(mp_pin_reset); - mp_hal_delay_ms(5); - - wait_for_busy_release(); - - // channel select - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x01); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00); - - // DC/DC frequency - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x06); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00); - - // high power mode osc - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x07); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x9d); - - // disable ADC - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x08); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00); - - // Vcom level - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x09); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0xd0, 0x00); - - // gate and source voltage levels - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x04); - - // GS - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00); - - mp_hal_delay_ms(5); - - // driver latch on - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x03); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x01); - - // driver latch off - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x03); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00); - - mp_hal_delay_ms(5); - - // charge pump positive voltage on - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x05); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x01); - - // final delay before PWM off - mp_hal_delay_us(30); - - // stop the pwm - hal_pwm_stop(mp_pwm_instance); - - // charge pump negative voltage on - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x05); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x03); - - mp_hal_delay_us(30); - - // Vcom driver on - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x05); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x0f); - - mp_hal_delay_ms(30); - - // output enable to disable - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x02); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x24); -} - -static void epaper_sld00200p_line(uint16_t line, const uint8_t * data, uint8_t fixed_value, epd_stage_t stage) -{ - mp_hal_delay_ms(10); - - DATA_WRITE(0x70, 0x04); - wait_for_busy_release(); - - // gate source - DATA_WRITE(0x72, 0x00); - wait_for_busy_release(); - - DATA_WRITE(0x70, 0x0a); - wait_for_busy_release(); - - mp_hal_pin_low(mp_pin_cs); - raw_write(0x72); - wait_for_busy_release(); - - uint16_t bytes_per_line = 264 / 8; - - // even pixels - for (uint16_t i = bytes_per_line; i > 0; --i) { - if (data != NULL) { - uint8_t pixels = data[i - 1] & 0xaa; - - switch (stage) { - case EPD_COMP: - // B -> W, W -> B (current image) - pixels = 0xaa | ((pixels ^ 0xaa) >> 1); - break; - - case EPD_WHITE: - // B -> N, W -> W (current image) - pixels = 0x55 + ((pixels ^ 0xaa) >> 1); - break; - - case EPD_INV: - // B -> N, W -> B (new image) - pixels = 0x55 | (pixels ^ 0xaa); - break; - - case EPD_NORM: - // B -> B, W -> W (new image) - pixels = 0xaa | (pixels >> 1); - break; - - default: - break; - } - - raw_write(pixels); - wait_for_busy_release(); - } else { - raw_write(fixed_value); - wait_for_busy_release(); - } - } - - uint16_t bytes_per_scan = 176 / 4; - // scan line - for (uint16_t i = 0; i < bytes_per_scan; i++) { - if (line / 4 == i) { - raw_write(0xc0 >> (2 * (line & 0x03))); - wait_for_busy_release(); - } else { - raw_write(0x00); - wait_for_busy_release(); - } - } - - // odd pixels - for (uint16_t i = 0; i < bytes_per_line; i++) { - if (data != NULL) { - uint8_t pixels; - pixels = data[i] & 0x55; - - switch (stage) { - case EPD_COMP: - pixels = 0xaa | (pixels ^ 0x55); - break; - - case EPD_WHITE: - pixels = 0x55 + (pixels ^ 0x55); - break; - - case EPD_INV: - pixels = 0x55 | ((pixels ^ 0x55) << 1); - break; - - case EPD_NORM: - pixels = 0xaa | pixels; - break; - - default: - break; - } - - uint8_t p1 = (pixels >> 6) & 0x03; - uint8_t p2 = (pixels >> 4) & 0x03; - uint8_t p3 = (pixels >> 2) & 0x03; - uint8_t p4 = (pixels >> 0) & 0x03; - pixels = (p1 << 0) | (p2 << 2) | (p3 << 4) | (p4 << 6); - - raw_write(pixels); - wait_for_busy_release(); - } else { - raw_write(fixed_value); - wait_for_busy_release(); - } - } - - // Complete line - raw_write(0x00); - wait_for_busy_release(); - - mp_hal_pin_high(mp_pin_cs); - wait_for_busy_release(); - - DATA_WRITE(0x70, 0x02); - wait_for_busy_release(); - - DATA_WRITE(0x72, 0x2f); -} - -void driver_sld00200p_deinit(void) { - epaper_sld00200p_line(0x7fffu, 0, 0x55, EPD_NORM); - mp_hal_delay_ms(25); - mp_hal_pin_low(mp_pin_border); - mp_hal_delay_ms(250); - mp_hal_pin_high(mp_pin_border); - - // latch reset turn on - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x03); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x01); - - // output enable off - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x02); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x05); - - // Vcom power off - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x05); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x0e); - - // power off negative charge pump - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x05); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x02); - - // discharge - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x04); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x0c); - mp_hal_delay_us(120); - - // all charge pumps off - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x05); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00); - - // turn of osc - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x07); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x0d); - - // discharge internal - 1 - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x04); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x50); - mp_hal_delay_us(40); - - // discharge internal - 2 - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x04); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0xA0); - mp_hal_delay_us(40); - - // discharge internal - 3 - mp_hal_delay_us(10); - DATA_WRITE(0x70, 0x04); - mp_hal_delay_us(10); - DATA_WRITE(0x72, 0x00); - - // turn of power and all signals - mp_hal_delay_ms(10); - mp_hal_pin_low(mp_pin_reset); - mp_hal_pin_low(mp_pin_panel_on); - mp_hal_pin_low(mp_pin_border); - - // discharge pulse - mp_hal_pin_high(mp_pin_discharge); - mp_hal_delay_us(250); - mp_hal_pin_low(mp_pin_discharge); - mp_hal_pin_high(mp_pin_cs); -} - -void driver_sld00200p_clear(uint16_t color) { - uint16_t line_count = 176; - for (uint16_t i = 0; i < line_count; i++) { - epaper_sld00200p_line(i, NULL, 0xFF, EPD_COMP); - } - mp_hal_delay_ms(100); - - for (uint16_t i = 0; i < line_count; i++) { - epaper_sld00200p_line(i, NULL, 0xAA, EPD_WHITE); - } - mp_hal_delay_ms(100); - - for (uint16_t i = 0; i < line_count; i++) { - epaper_sld00200p_line(i, NULL, 0xFF, EPD_INV); - } - mp_hal_delay_ms(100); - - for (uint16_t i = 0; i < line_count; i++) { - epaper_sld00200p_line(i, NULL, 0xAA, EPD_NORM); - } - mp_hal_delay_ms(100); -} - -void driver_sld00200p_update_line(uint16_t line, framebuffer_byte_t * p_bytes, framebuffer_byte_t * p_old, uint16_t len) { - epaper_sld00200p_line(line, (uint8_t *)p_old, 0x00, EPD_COMP); - epaper_sld00200p_line(line, (uint8_t *)p_old, 0xAA, EPD_WHITE); - epaper_sld00200p_line(line, (uint8_t *)p_bytes, 0xAA, EPD_INV); - epaper_sld00200p_line(line, (uint8_t *)p_bytes, 0xFF, EPD_NORM); -} - -#endif diff --git a/nrf5/modules/display/epaper_sld00200p_driver.h b/nrf5/modules/display/epaper_sld00200p_driver.h deleted file mode 100644 index 81470d0ab..000000000 --- a/nrf5/modules/display/epaper_sld00200p_driver.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef EPAPER_SLD00200P_DRIVER_H__ -#define EPAPER_SLD00200P_DRIVER_H__ - -#if NRF52 // TODO: For now only supported by NRF52 targets, as PWM soft-pwm is not present for nrf51 yet. - -#include "py/mphal.h" - -#include "hal_spi.h" -#include "hal_pwm.h" -#include "framebuffer.h" - -typedef enum -{ - EPD_COMP, - EPD_WHITE, - EPD_INV, - EPD_NORM -} epd_stage_t; - -void driver_sld00200p_init(NRF_SPI_Type * p_spi_instance, - NRF_PWM_Type * p_pwm_instance, - pin_obj_t * p_pin_cs, - pin_obj_t * p_pin_panel_on, - pin_obj_t * p_pin_border, - pin_obj_t * p_pin_busy, - pin_obj_t * p_pin_reset, - pin_obj_t * p_pin_discharge); - -void driver_sld00200p_reinit(void); - -void driver_sld00200p_deinit(void); - -void driver_sld00200p_clear(uint16_t color); - -void driver_sld00200p_update_line(uint16_t line, framebuffer_byte_t * p_bytes, framebuffer_byte_t * p_bytes_old, uint16_t len); - -#endif // NRF52 - -#endif // EPAPER_SLD00200P_DRIVER_H__ diff --git a/nrf5/modules/display/epaper_sld00200p_obj.c b/nrf5/modules/display/epaper_sld00200p_obj.c deleted file mode 100644 index df2d5d6d9..000000000 --- a/nrf5/modules/display/epaper_sld00200p_obj.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "genhdr/pins.h" - -#include "epaper_sld00200p_driver.h" - -// For now PWM is only enabled for nrf52 targets. -#if MICROPY_PY_DISPLAY_EPAPER_SLD00200P && NRF52 - -/// \moduleref epaper -/// \class sld00200p - SLD00200P E-paper shield. - -#include "pin.h" -#include "spi.h" -#include "pwm.h" -#include "hal_spi.h" -#include "hal_pwm.h" -#include "moddisplay.h" -#include "framebuffer.h" - -typedef struct _epaper_sld00200p_obj_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; - framebuffer_t * framebuffer; - machine_hard_spi_obj_t *spi; - machine_hard_pwm_obj_t *pwm; - pin_obj_t * pin_cs; - pin_obj_t * pin_panel_on; - pin_obj_t * pin_border; - pin_obj_t * pin_busy; - pin_obj_t * pin_reset; - pin_obj_t * pin_discharge; -#if 0 - pin_obj_t * pin_temp_sensor; -#endif -} epaper_sld00200p_obj_t; - -#define EPAPER_SLD00200P_COLOR_BLACK 0 -#define EPAPER_SLD00200P_COLOR_WHITE 1 - -static void set_pixel(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color) { - epaper_sld00200p_obj_t *self = (epaper_sld00200p_obj_t *)p_display; - - if (color == EPAPER_SLD00200P_COLOR_BLACK) { - framebuffer_pixel_clear(self->framebuffer, x, y); - } else { - framebuffer_pixel_set(self->framebuffer, x, y); - } -} - -/// \method __str__() -/// Return a string describing the SLD00200P object. -STATIC void epaper_sld00200_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - epaper_sld00200p_obj_t *self = o; - - mp_printf(print, "SLD00200(SPI(mosi=(port=%u, pin=%u), miso=(port=%u, pin=%u), clk=(port=%u, pin=%u)),\n", - self->spi->pyb->spi->init.mosi_pin->port, - self->spi->pyb->spi->init.mosi_pin->pin, - self->spi->pyb->spi->init.miso_pin->port, - self->spi->pyb->spi->init.miso_pin->pin, - self->spi->pyb->spi->init.clk_pin->port, - self->spi->pyb->spi->init.clk_pin->pin); - - mp_printf(print, " PWM(pwm_pin=%u),\n", - self->pwm->pyb->pwm->init.pwm_pin); - - mp_printf(print, " cs=(port=%u, pin=%u), panel_on=(port=%u, pin=%u),\n", - self->pin_cs->port, - self->pin_cs->pin, - self->pin_panel_on->port, - self->pin_panel_on->pin); - - mp_printf(print, " border=(port=%u, pin=%u), busy=(port=%u, pin=%u),\n", - self->pin_border->port, - self->pin_border->pin, - self->pin_busy->port, - self->pin_busy->pin); - - mp_printf(print, " reset=(port=%u, pin=%u), discharge=(port=%u, pin=%u),\n", - self->pin_reset->port, - self->pin_reset->pin, - self->pin_discharge->port, - self->pin_discharge->pin); - - mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n", - self->framebuffer->screen_width, - self->framebuffer->screen_height, - self->framebuffer->line_orientation, - self->framebuffer->fb_stride, - self->framebuffer->fb_dirty_stride); -} - -// for make_new -enum { - ARG_NEW_WIDTH, - ARG_NEW_HEIGHT, - ARG_NEW_SPI, - ARG_NEW_PWM, - ARG_NEW_CS, - ARG_NEW_PANEL_ON, - ARG_NEW_BORDER, - ARG_NEW_BUSY, - ARG_NEW_RESET, - ARG_NEW_DISCHARGE, - ARG_NEW_TEMP_SENSOR, -}; - -/* -from machine import Pin, SPI, PWM -from display import SLD00200P -import draw -reset = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP) -panel_on = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -discharge = Pin("A19", mode=Pin.OUT, pull=Pin.PULL_UP) -border = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) -busy = Pin("A18", mode=Pin.IN, pull=Pin.PULL_DISABLED) -cs = Pin("A22", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -pwm = PWM(0, Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP), freq=PWM.FREQ_250KHZ, duty=50, period=2) -d = SLD00200P(264, 176, spi, pwm, cs, panel_on, border, busy, reset, discharge) -draw.text(d, "Hello World!", 32, 32) -d.show() - -Example for nrf52840 / pca10056: - -from machine import Pin, SPI, PWM -from display import SLD00200P -import draw -reset = Pin("B7", mode=Pin.OUT, pull=Pin.PULL_UP) -panel_on = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP) -discharge = Pin("B9", mode=Pin.OUT, pull=Pin.PULL_UP) -border = Pin("B4", mode=Pin.OUT, pull=Pin.PULL_UP) -busy = Pin("B8", mode=Pin.IN, pull=Pin.PULL_DISABLED) -cs = Pin("B12", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -pwm = PWM(0, Pin("B6", mode=Pin.OUT, pull=Pin.PULL_UP), freq=PWM.FREQ_250KHZ, duty=50, period=2) -d = SLD00200P(264, 176, spi, pwm, cs, panel_on, border, busy, reset, discharge) -draw.text(d, "Hello World!", 32, 32) -d.show() - -*/ -STATIC mp_obj_t epaper_sld00200p_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - static const mp_arg_t allowed_args[] = { - { ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_SPI, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_PWM, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_PANEL_ON, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_BORDER, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_BUSY, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_RESET, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_DISCHARGE, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, -#if 0 - { ARG_NEW_TEMP_SENSOR, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, -#endif - }; - - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - epaper_sld00200p_obj_t *s = m_new_obj_with_finaliser(epaper_sld00200p_obj_t); - s->base.type = type; - s->draw_callbacks.pixel_set = set_pixel; - - mp_int_t width; - mp_int_t height; - - if (args[ARG_NEW_WIDTH].u_int > 0) { - width = args[ARG_NEW_WIDTH].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display width not set")); - } - - if (args[ARG_NEW_HEIGHT].u_int > 0) { - height = args[ARG_NEW_HEIGHT].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display height not set")); - } - - if (args[ARG_NEW_SPI].u_obj != MP_OBJ_NULL) { - s->spi = args[ARG_NEW_SPI].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display SPI not set")); - } - - if (args[ARG_NEW_PWM].u_obj != MP_OBJ_NULL) { - s->pwm = args[ARG_NEW_PWM].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display PWM not set")); - } - - if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) { - s->pin_cs = args[ARG_NEW_CS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display CS Pin not set")); - } - - if (args[ARG_NEW_PANEL_ON].u_obj != MP_OBJ_NULL) { - s->pin_panel_on = args[ARG_NEW_PANEL_ON].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Panel-on Pin not set")); - } - - if (args[ARG_NEW_BORDER].u_obj != MP_OBJ_NULL) { - s->pin_border = args[ARG_NEW_BORDER].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Border Pin not set")); - } - - if (args[ARG_NEW_BUSY].u_obj != MP_OBJ_NULL) { - s->pin_busy = args[ARG_NEW_BUSY].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Busy Pin not set")); - } - - if (args[ARG_NEW_RESET].u_obj != MP_OBJ_NULL) { - s->pin_reset = args[ARG_NEW_RESET].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Reset Pin not set")); - } - - if (args[ARG_NEW_DISCHARGE].u_obj != MP_OBJ_NULL) { - s->pin_discharge = args[ARG_NEW_DISCHARGE].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Reset Pin not set")); - } - -#if 0 - if (args[ARG_NEW_TEMP_SENSOR].u_obj != MP_OBJ_NULL) { - s->pin_temp_sensor = args[ARG_NEW_TEMP_SENSOR].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Busy Pin not set)")); - } -#endif - - framebuffer_init_t init_conf = { - .width = width, - .height = height, - .line_orientation = FRAMEBUFFER_LINE_DIR_HORIZONTAL, - .double_buffer = false - }; - - s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t)); - - framebuffer_init(s->framebuffer, &init_conf); - - driver_sld00200p_init(s->spi->pyb->spi->instance, - s->pwm->pyb->pwm->instance, - s->pin_cs, - s->pin_panel_on, - s->pin_border, - s->pin_busy, - s->pin_reset, - s->pin_discharge); - - // Default to white background - driver_sld00200p_clear(0x00); - - framebuffer_clear(s->framebuffer); - - driver_sld00200p_deinit(); - - return MP_OBJ_FROM_PTR(s); -} - -// text - -/// \method fill(color) -/// Fill framebuffer with the color defined as argument. -STATIC mp_obj_t epaper_sld00200p_fill(mp_obj_t self_in, mp_obj_t color) { - epaper_sld00200p_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (color == MP_OBJ_NEW_SMALL_INT(EPAPER_SLD00200P_COLOR_BLACK)) { - framebuffer_clear(self->framebuffer); - } else { - framebuffer_fill(self->framebuffer); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(epaper_sld00200p_fill_obj, epaper_sld00200p_fill); - -static void render(framebuffer_t * p_framebuffer, bool refresh) { - for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) { - if (p_framebuffer->fb_dirty[i].byte != 0 || refresh) { - for (uint16_t b = 0; b < 8; b++) { - if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1) || refresh) { - uint16_t line_num = (i * 8) + b; - driver_sld00200p_update_line(line_num, - &p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride], - &p_framebuffer->fb_old[line_num * p_framebuffer->fb_stride], - p_framebuffer->fb_stride); - } - } - - if (refresh == false) { - p_framebuffer->fb_dirty[i].byte = 0x00; - } - } - } -} - -/// \method show([num_of_refresh]) -/// Display content in framebuffer. -/// -/// - With no argument, no refresh is done. -/// - With `num_of_refresh` given, the lines touched by previous update -/// will be refreshed the given number of times. If no lines have been -/// touched, no update will be performed. To force a refresh, call the -/// refresh() method explicitly. -STATIC mp_obj_t epaper_sld00200p_show(size_t n_args, const mp_obj_t *args) { - epaper_sld00200p_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - mp_int_t num_of_refresh = 0; - - if (n_args > 1) { - num_of_refresh = mp_obj_get_int(args[1]); - } - driver_sld00200p_reinit(); - - render(self->framebuffer, false); - framebuffer_flip(self->framebuffer); - - if (num_of_refresh > 0) { - while (num_of_refresh > 0) { - render(self->framebuffer, true); - num_of_refresh--; - } - } - - driver_sld00200p_deinit(); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(epaper_sld00200p_show_obj, 1, 2, epaper_sld00200p_show); - -/// \method refresh([num_of_refresh]) -/// Refresh content in framebuffer. -/// -/// - With no argument, 1 refresh will be done. -/// - With `num_of_refresh` given, The whole framebuffer will be considered -/// dirty and will be refreshed the given number of times. -STATIC mp_obj_t epaper_sld00200p_refresh(size_t n_args, const mp_obj_t *args) { - epaper_sld00200p_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - mp_int_t num_of_refresh = 0; - - if (n_args > 1) { - num_of_refresh = mp_obj_get_int(args[1]); - } - - driver_sld00200p_reinit(); - - if (num_of_refresh > 0) { - while (num_of_refresh > 0) { - render(self->framebuffer, true); - num_of_refresh--; - } - } else { - // default to one refresh - render(self->framebuffer, true); - } - - driver_sld00200p_deinit(); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(epaper_sld00200p_refresh_obj, 1, 2, epaper_sld00200p_refresh); - -/// \method pixel(x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color of the pixel in framebuffer will be returend. -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t epaper_sld00200p_pixel(size_t n_args, const mp_obj_t *args) { - epaper_sld00200p_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_int_t x = mp_obj_get_int(args[1]); - mp_int_t y = mp_obj_get_int(args[2]); - mp_int_t color = mp_obj_get_int(args[3]); - - set_pixel(self, x, y, color); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(epaper_sld00200p_pixel_obj, 3, 4, epaper_sld00200p_pixel); - -/// \method pixel(text, x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color will be the opposite of background (fill color). -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t epaper_sld00200p_text(size_t n_args, const mp_obj_t *args) { - epaper_sld00200p_obj_t *self = MP_OBJ_TO_PTR(args[0]); - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color; - if (n_args >= 4) { - color = mp_obj_get_int(args[3]); - } - -// display_print_string(self->framebuffer, x, y, str); - - (void)x; - (void)y; - (void)self; - (void)str; - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(epaper_sld00200p_text_obj, 4, 5, epaper_sld00200p_text); - - -STATIC mp_obj_t epaper_sld00200p_del(mp_obj_t self_in) { - epaper_sld00200p_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(epaper_sld00200p_del_obj, epaper_sld00200p_del); - -STATIC const mp_rom_map_elem_t epaper_sld00200p_locals_dict_table[] = { - { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&epaper_sld00200p_del_obj) }, - { MP_ROM_QSTR(MP_QSTR_fill), MP_ROM_PTR(&epaper_sld00200p_fill_obj) }, - { MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&epaper_sld00200p_show_obj) }, - { MP_ROM_QSTR(MP_QSTR_refresh), MP_ROM_PTR(&epaper_sld00200p_refresh_obj) }, - { MP_ROM_QSTR(MP_QSTR_text), MP_ROM_PTR(&epaper_sld00200p_text_obj) }, - { MP_ROM_QSTR(MP_QSTR_pixel), MP_ROM_PTR(&epaper_sld00200p_pixel_obj) }, -#if 0 - { MP_ROM_QSTR(MP_QSTR_bitmap), MP_ROM_PTR(&epaper_sld00200p_bitmap_obj) }, -#endif - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(EPAPER_SLD00200P_COLOR_BLACK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(EPAPER_SLD00200P_COLOR_WHITE) }, - -}; - -STATIC MP_DEFINE_CONST_DICT(epaper_sld00200p_locals_dict, epaper_sld00200p_locals_dict_table); - - -const mp_obj_type_t epaper_sld00200p_type = { - { &mp_type_type }, - .name = MP_QSTR_SLD00200P, - .print = epaper_sld00200_print, - .make_new = epaper_sld00200p_make_new, - .locals_dict = (mp_obj_t)&epaper_sld00200p_locals_dict -}; - -#endif // MICROPY_PY_DISPLAY_EPAPER_SLD00200P diff --git a/nrf5/modules/display/epaper_sld00200p_obj.h b/nrf5/modules/display/epaper_sld00200p_obj.h deleted file mode 100644 index f6a3fa8ed..000000000 --- a/nrf5/modules/display/epaper_sld00200p_obj.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef EPAPER_SLD00200P_H__ -#define EPAPER_SLD00200P_H__ - -#include <py/obj.h> - -extern const mp_obj_type_t epaper_sld00200p_type; - -#endif // EPAPER_SLD00200P_H__ - diff --git a/nrf5/modules/display/framebuffer.c b/nrf5/modules/display/framebuffer.c deleted file mode 100644 index 988c7715e..000000000 --- a/nrf5/modules/display/framebuffer.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdio.h> - -#include <string.h> -#include "py/obj.h" -#include "framebuffer.h" - -#if MICROPY_PY_DISPLAY_FRAMEBUFFER - -void framebuffer_init(framebuffer_t * p_fb, framebuffer_init_t * p_init_conf) { - uint16_t width = p_init_conf->width; - uint16_t height = p_init_conf->height; - - if (p_init_conf->line_orientation == FRAMEBUFFER_LINE_DIR_HORIZONTAL) { - uint16_t dirty_row_stride = height / 8; - p_fb->fb_dirty = m_new(framebuffer_byte_t, dirty_row_stride); - p_fb->fb_dirty_stride = dirty_row_stride; - p_fb->fb_stride = width / 8; - } else { // FRAMEBUFFER_LINE_DIR_VERTICAL - uint16_t dirty_column_stride = width / 8; - p_fb->fb_dirty = m_new(framebuffer_byte_t, dirty_column_stride); - p_fb->fb_dirty_stride = dirty_column_stride; - p_fb->fb_stride = height / 8; - } - - p_fb->fb_new = m_new(framebuffer_byte_t, (width * height / 8)); - - if (p_init_conf->double_buffer) { - p_fb->fb_old = m_new(framebuffer_byte_t, (width * height / 8)); - } - p_fb->line_orientation = p_init_conf->line_orientation; - p_fb->screen_width = width; - p_fb->screen_height = height; -} - - -void framebuffer_flip(framebuffer_t * p_fb) { - if (p_fb->fb_double) { - framebuffer_byte_t * old = p_fb->fb_old; - p_fb->fb_old = p_fb->fb_new; - p_fb->fb_new = old; - } -} - -void framebuffer_pixel_set(framebuffer_t * p_fb, uint16_t x, uint16_t y) { - if (p_fb->line_orientation == FRAMEBUFFER_LINE_DIR_HORIZONTAL) { - uint16_t col = (x / 8); - uint16_t row = y; - uint8_t bit_pos = x % 8; - - p_fb->fb_new[row * (p_fb->fb_stride) + col].byte |= (1 << bit_pos); - p_fb->fb_dirty[y / 8].byte |= (uint8_t)(0x1 << y % 8); - } else { - uint16_t col = x; - uint16_t row = (y / 8); - uint8_t bit_pos = y % 8; - - p_fb->fb_new[col * (p_fb->fb_stride) + row].byte |= (1 << bit_pos); - p_fb->fb_dirty[x / 8].byte |= (uint8_t)(0x1 << x % 8); - } -} - -void framebuffer_pixel_clear(framebuffer_t * p_fb, uint16_t x, uint16_t y) { - if (p_fb->line_orientation == FRAMEBUFFER_LINE_DIR_HORIZONTAL) { - uint16_t col = (x / 8); - uint16_t row = y; - uint8_t bit_pos = x % 8; - - p_fb->fb_new[row * (p_fb->fb_stride) + col].byte &= ~(1 << bit_pos); - p_fb->fb_dirty[y / 8].byte |= (uint8_t)(0x1 << y % 8); - } else { - uint16_t col = x; - uint16_t row = (y / 8); - uint8_t bit_pos = y % 8; - - p_fb->fb_new[col * (p_fb->fb_stride) + row].byte &= ~(1 << bit_pos); - p_fb->fb_dirty[x / 8].byte |= (uint8_t)(0x1 << x % 8); - } -} - -void framebuffer_clear(framebuffer_t * p_fb) { - memset(p_fb->fb_new, 0x00, p_fb->screen_width * p_fb->screen_height / 8); - memset(p_fb->fb_dirty, 0xFF, p_fb->fb_dirty_stride); -} - -void framebuffer_fill(framebuffer_t * p_fb) { - memset(p_fb->fb_new, 0xFF, p_fb->screen_width * p_fb->screen_height / 8); - memset(p_fb->fb_dirty, 0xFF, p_fb->fb_dirty_stride); -} - -#endif // MICROPY_PY_DISPLAY_FRAMEBUFFER diff --git a/nrf5/modules/display/framebuffer.h b/nrf5/modules/display/framebuffer.h deleted file mode 100644 index 1c9ad05b7..000000000 --- a/nrf5/modules/display/framebuffer.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef DISPLAY_FRAMEBUFFER_H__ -#define DISPLAY_FRAMEBUFFER_H__ - -#include <stdint.h> -#include <stdbool.h> - -typedef struct { - uint8_t bit0 : 1; - uint8_t bit1 : 1; - uint8_t bit2 : 1; - uint8_t bit3 : 1; - uint8_t bit4 : 1; - uint8_t bit5 : 1; - uint8_t bit6 : 1; - uint8_t bit7 : 1; -} bits_le_t; - -typedef struct { - uint8_t bit7 : 1; - uint8_t bit6 : 1; - uint8_t bit5 : 1; - uint8_t bit4 : 1; - uint8_t bit3 : 1; - uint8_t bit2 : 1; - uint8_t bit1 : 1; - uint8_t bit0 : 1; -} bits_be_t; - -typedef struct { - union { - uint8_t byte; - bits_le_t bits_le; - bits_be_t bits_be; - }; -} framebuffer_byte_t; - -typedef enum { - FRAMEBUFFER_LINE_DIR_HORIZONTAL, - FRAMEBUFFER_LINE_DIR_VERTICAL -} framebuffer_line_orientation_t; - -typedef struct { - framebuffer_byte_t * fb_new; - framebuffer_byte_t * fb_old; - uint16_t fb_stride; - bool fb_double; - framebuffer_byte_t * fb_dirty; - uint16_t fb_dirty_stride; - uint16_t fb_orientation; - uint16_t screen_height; - uint16_t screen_width; - framebuffer_line_orientation_t line_orientation; -} framebuffer_t; - -typedef struct { - uint16_t width; - uint16_t height; - framebuffer_line_orientation_t line_orientation; - bool double_buffer; -} framebuffer_init_t; - -void framebuffer_init(framebuffer_t * p_fb, framebuffer_init_t * p_init_conf); -void framebuffer_deinit(framebuffer_t * p_fb); - -void framebuffer_flip(framebuffer_t * p_fb); -void framebuffer_pixel_set(framebuffer_t * p_fb, uint16_t x, uint16_t y); -void framebuffer_pixel_clear(framebuffer_t * p_fb, uint16_t x, uint16_t y); -void framebuffer_clear(framebuffer_t * p_fb); -void framebuffer_fill(framebuffer_t * p_fb); - -#endif // DISPLAY_FRAMEBUFFER_H__ diff --git a/nrf5/modules/display/lcd_ili9341_driver.c b/nrf5/modules/display/lcd_ili9341_driver.c deleted file mode 100644 index b6c4b2f7f..000000000 --- a/nrf5/modules/display/lcd_ili9341_driver.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/mphal.h" - -#include "lcd_ili9341_driver.h" -#include "hal_spi.h" -#include "hal_time.h" - -#if MICROPY_PY_DISPLAY_LCD_ILI9341 - -static pin_obj_t * mp_cs_pin; -static pin_obj_t * mp_dc_pin; -static NRF_SPI_Type * mp_instance; - - -static void raw_write(uint8_t value) -{ - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); -} - -static void cmd_write(uint8_t value) -{ - mp_hal_pin_low(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); - - mp_hal_pin_high(mp_cs_pin); -} - -static void data_write(uint8_t value) -{ - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); - - mp_hal_pin_high(mp_cs_pin); -} - -void driver_ili9341_init(NRF_SPI_Type * p_instance, pin_obj_t * p_cs_pin, pin_obj_t * p_dc_pin) -{ - mp_instance = p_instance; - mp_cs_pin = p_cs_pin; - mp_dc_pin = p_dc_pin; -#if 0 - mp_hal_pin_high(enable_pin); - mp_hal_pin_high(backlight_pin); -#endif - - mp_hal_pin_high(mp_cs_pin); - mp_hal_pin_high(mp_dc_pin); - - // Read driver id - - mp_hal_delay_ms(1000); - - cmd_write(0x01); - - mp_hal_delay_ms(500); - - cmd_write(0xCF); - data_write(0x00); - data_write(0x8B); - data_write(0X30); - - cmd_write(0xED); - data_write(0x67); - data_write(0x03); - data_write(0X12); - data_write(0X81); - - cmd_write(0xE8); - data_write(0x85); - data_write(0x10); - data_write(0x7A); - - cmd_write(0xCB); - data_write(0x39); - data_write(0x2C); - data_write(0x00); - data_write(0x34); - data_write(0x02); - - cmd_write(0xF7); - data_write(0x20); - - cmd_write(0xEA); - data_write(0x00); - data_write(0x00); - - cmd_write(0xC0); /* Power control */ - data_write(0x1B); /* VRH[5:0] */ - - cmd_write(0xC1); /* Power control */ - data_write(0x10); /* SAP[2:0];BT[3:0] */ - - cmd_write(0xC5); /* VCM control */ - data_write(0x3F); - data_write(0x3C); - - cmd_write(0xC7); /* VCM control2 */ - data_write(0XB7); - - cmd_write(0x36); /* Memory Access Control */ - data_write(0x08); - - cmd_write(0x3A); - data_write(0x55); - - cmd_write(0xB1); - data_write(0x00); - data_write(0x1B); - - cmd_write(0xB6); /* Display Function Control */ - data_write(0x0A); - data_write(0xA2); - - cmd_write(0xF2); /* 3Gamma Function Disable */ - data_write(0x00); - - cmd_write(0x26); /* Gamma curve selected */ - data_write(0x01); - - cmd_write(0xE0); /* Set Gamma */ - data_write(0x0F); - data_write(0x2A); - data_write(0x28); - data_write(0x08); - data_write(0x0E); - data_write(0x08); - data_write(0x54); - data_write(0XA9); - data_write(0x43); - data_write(0x0A); - data_write(0x0F); - data_write(0x00); - data_write(0x00); - data_write(0x00); - data_write(0x00); - - cmd_write(0XE1); /* Set Gamma */ - data_write(0x00); - data_write(0x15); - data_write(0x17); - data_write(0x07); - data_write(0x11); - data_write(0x06); - data_write(0x2B); - data_write(0x56); - data_write(0x3C); - data_write(0x05); - data_write(0x10); - data_write(0x0F); - data_write(0x3F); - data_write(0x3F); - data_write(0x0F); - - cmd_write(0x11); /* Exit Sleep */ - - mp_hal_delay_ms(120); - - cmd_write(0x29); /* Display on */ -} - -static void set_col(uint16_t start_col, uint16_t end_col) -{ - cmd_write(0x2A); /* Column Command address */ - data_write(start_col >> 8); - data_write(start_col & 0xFF ); - data_write(end_col >> 8); - data_write(end_col & 0xFF); -} - -static void set_page(uint16_t start_page, uint16_t end_page) -{ - cmd_write(0x2B); /* Column Command address */ - data_write(start_page >> 8); - data_write(start_page & 0xFF); - data_write(end_page >> 8); - data_write(end_page & 0xFF); -} - -void driver_ili9341_clear(uint16_t color) -{ - set_col(0, 239); - set_page(0, 319); - - cmd_write(0x2c); // start writing to the display ram - - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - for(uint16_t i = 0; i < 38400; i++) - { - raw_write(color >> 8); - raw_write(color & 0xFF); - raw_write(color >> 8); - raw_write(color & 0xFF); - } - - mp_hal_pin_high(mp_cs_pin); -} - -void driver_ili9341_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len) { - set_col(0, 239); - set_page(line, line); - - cmd_write(0x2c); - - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - for (uint16_t i = 0; i < len; i++) { - uint8_t byte = (uint8_t)((uint8_t *)p_bytes)[i]; - for (uint8_t pixel_pos = 0; pixel_pos < 8; pixel_pos++) { - if (((byte >> pixel_pos) & 0x1) == 0x0) { - data_write(0x00); - data_write(0x00); - } else { - data_write(0xFF); - data_write(0xFF); - } - } - } - - mp_hal_pin_high(mp_cs_pin); -} - -#endif diff --git a/nrf5/modules/display/lcd_ili9341_driver.h b/nrf5/modules/display/lcd_ili9341_driver.h deleted file mode 100644 index aa01ecfaa..000000000 --- a/nrf5/modules/display/lcd_ili9341_driver.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef LCD_ILI9341_DRIVER_H__ -#define LCD_ILI9341_DRIVER_H__ - -#include "py/mphal.h" - -#include "hal_spi.h" -#include "framebuffer.h" - -void driver_ili9341_init(NRF_SPI_Type * p_instance, pin_obj_t * cs_pin, pin_obj_t * dc_pin); - -void driver_ili9341_clear(uint16_t color); - -void driver_ili9341_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len); - -#endif // LCD_ILI9341_DRIVER_H__ diff --git a/nrf5/modules/display/lcd_ili9341_obj.c b/nrf5/modules/display/lcd_ili9341_obj.c deleted file mode 100644 index 968b3bf85..000000000 --- a/nrf5/modules/display/lcd_ili9341_obj.c +++ /dev/null @@ -1,357 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdio.h> - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "genhdr/pins.h" - -#include "lcd_ili9341_driver.h" -// For now PWM is only enabled for nrf52 targets. -#if MICROPY_PY_DISPLAY_LCD_ILI9341 - -/// \moduleref display -/// \class ILI9341 - ILI9341 TFT LCD display driver. - -#include "moddisplay.h" -#include "framebuffer.h" -#include "pin.h" -#include "spi.h" - -typedef struct _lcd_ili9341_obj_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; - framebuffer_t * framebuffer; - machine_hard_spi_obj_t *spi; - pin_obj_t * pin_cs; - pin_obj_t * pin_dc; -} lcd_ili9341_obj_t; - -#define LCD_ILI9341_COLOR_BLACK 0 -#define LCD_ILI9341_COLOR_WHITE 1 - -static void set_pixel(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color) { - lcd_ili9341_obj_t *self = (lcd_ili9341_obj_t *)p_display; - - if (color == LCD_ILI9341_COLOR_BLACK) { - framebuffer_pixel_clear(self->framebuffer, x, y); - } else { - framebuffer_pixel_set(self->framebuffer, x, y); - } -} - -/// \method __str__() -/// Return a string describing the ILI9341 object. -STATIC void lcd_ili9341_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - lcd_ili9341_obj_t *self = o; - - mp_printf(print, "ILI9341(SPI(mosi=(port=%u, pin=%u), miso=(port=%u, pin=%u), clk=(port=%u, pin=%u)),\n", - self->spi->pyb->spi->init.mosi_pin->port, - self->spi->pyb->spi->init.mosi_pin->pin, - self->spi->pyb->spi->init.miso_pin->port, - self->spi->pyb->spi->init.miso_pin->pin, - self->spi->pyb->spi->init.clk_pin->port, - self->spi->pyb->spi->init.clk_pin->pin); - - mp_printf(print, " cs=(port=%u, pin=%u), dc=(port=%u, pin=%u),\n", - self->pin_cs->port, - self->pin_cs->pin, - self->pin_dc->port, - self->pin_dc->pin); - - mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n", - self->framebuffer->screen_width, - self->framebuffer->screen_height, - self->framebuffer->line_orientation, - self->framebuffer->fb_stride, - self->framebuffer->fb_dirty_stride); -} - -// for make_new -enum { - ARG_NEW_WIDTH, - ARG_NEW_HEIGHT, - ARG_NEW_SPI, - ARG_NEW_CS, - ARG_NEW_DC, -}; - -/* - -Example for nrf51822 / pca10028: - -from machine import Pin, SPI -from display import ILI9341 -cs = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("A18", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = ILI9341(240, 320, spi, cs, dc) -d.text("Hello World!", 32, 32) -d.show() - -Example for nrf52832 / pca10040: - -from machine import Pin, SPI -from display import ILI9341 -cs = Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = ILI9341(240, 320, spi, cs, dc) -d.text("Hello World!", 32, 32) -d.show() - -Example for nrf52840 / pca10056: - -from machine import Pin, SPI -from display import ILI9341 -cs = Pin("B6", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("B7", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = ILI9341(240, 320, spi, cs, dc) -d.text("Hello World!", 32, 32) -d.show() - -*/ -STATIC mp_obj_t lcd_ili9341_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - static const mp_arg_t allowed_args[] = { - { ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_SPI, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_DC, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - lcd_ili9341_obj_t *s = m_new_obj_with_finaliser(lcd_ili9341_obj_t); - s->base.type = type; - s->draw_callbacks.pixel_set = set_pixel; - - mp_int_t width; - mp_int_t height; - - if (args[ARG_NEW_WIDTH].u_int > 0) { - width = args[ARG_NEW_WIDTH].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display width not set")); - } - - if (args[ARG_NEW_HEIGHT].u_int > 0) { - height = args[ARG_NEW_HEIGHT].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display height not set")); - } - - if (args[ARG_NEW_SPI].u_obj != MP_OBJ_NULL) { - s->spi = args[ARG_NEW_SPI].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display SPI not set")); - } - - if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) { - s->pin_cs = args[ARG_NEW_CS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display CS Pin not set")); - } - - if (args[ARG_NEW_DC].u_obj != MP_OBJ_NULL) { - s->pin_dc = args[ARG_NEW_DC].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display DC Pin not set")); - } - - framebuffer_init_t init_conf = { - .width = width, - .height = height, - .line_orientation = FRAMEBUFFER_LINE_DIR_HORIZONTAL, - .double_buffer = false - }; - - s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t)); - - framebuffer_init(s->framebuffer, &init_conf); - - driver_ili9341_init(s->spi->pyb->spi->instance, s->pin_cs, s->pin_dc); - // Default to white background - driver_ili9341_clear(0x0000); - - framebuffer_clear(s->framebuffer); - - return MP_OBJ_FROM_PTR(s); -} - -// text - -/// \method fill(color) -/// Fill framebuffer with the color defined as argument. -STATIC mp_obj_t lcd_ili9341_fill(mp_obj_t self_in, mp_obj_t color) { - lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (color == MP_OBJ_NEW_SMALL_INT(LCD_ILI9341_COLOR_BLACK)) { - framebuffer_clear(self->framebuffer); - } else { - framebuffer_fill(self->framebuffer); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lcd_ili9341_fill_obj, lcd_ili9341_fill); - -static void render(framebuffer_t * p_framebuffer) { - for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) { - if (p_framebuffer->fb_dirty[i].byte != 0) { - for (uint16_t b = 0; b < 8; b++) { - if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1)) { - uint16_t line_num = (i * 8) + b; - driver_ili9341_update_line(line_num, - &p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride], - p_framebuffer->fb_stride); - } - } - - p_framebuffer->fb_dirty[i].byte = 0x00; - } - } -} - -/// \method show() -/// Display content in framebuffer. -STATIC mp_obj_t lcd_ili9341_show(size_t n_args, const mp_obj_t *args) { - lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - render(self->framebuffer); - framebuffer_flip(self->framebuffer); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ili9341_show_obj, 1, 2, lcd_ili9341_show); - -/// \method refresh([num_of_refresh]) -/// Refresh content in framebuffer. -/// -/// - With no argument, 1 refresh will be done. -/// - With `num_of_refresh` given, The whole framebuffer will be considered -/// dirty and will be refreshed the given number of times. -STATIC mp_obj_t lcd_ili9341_refresh(mp_obj_t self_in) { - lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_ili9341_refresh_obj, lcd_ili9341_refresh); - -/// \method pixel(x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color of the pixel in framebuffer will be returend. -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t lcd_ili9341_pixel(size_t n_args, const mp_obj_t *args) { - lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_int_t x = mp_obj_get_int(args[1]); - mp_int_t y = mp_obj_get_int(args[2]); - mp_int_t color = mp_obj_get_int(args[3]); - - set_pixel(self, x, y, color); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ili9341_pixel_obj, 3, 4, lcd_ili9341_pixel); - -/// \method pixel(text, x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color will be the opposite of background (fill color). -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t lcd_ili9341_text(size_t n_args, const mp_obj_t *args) { - lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(args[0]); - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color; - if (n_args >= 4) { - color = mp_obj_get_int(args[3]); - } - - // display_print_string(self->framebuffer, x, y, str); - - (void)x; - (void)y; - (void)self; - (void)str; - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ili9341_text_obj, 4, 5, lcd_ili9341_text); - -STATIC mp_obj_t lcd_ili9341_del(mp_obj_t self_in) { - lcd_ili9341_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_ili9341_del_obj, lcd_ili9341_del); - -STATIC const mp_map_elem_t lcd_ili9341_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)(&lcd_ili9341_del_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_fill), (mp_obj_t)(&lcd_ili9341_fill_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)(&lcd_ili9341_show_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)(&lcd_ili9341_text_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)(&lcd_ili9341_pixel_obj) }, -#if 0 - { MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&lcd_ili9341_bitmap_obj) }, -#endif - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(LCD_ILI9341_COLOR_BLACK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(LCD_ILI9341_COLOR_WHITE) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) }, -}; - -STATIC MP_DEFINE_CONST_DICT(lcd_ili9341_locals_dict, lcd_ili9341_locals_dict_table); - -const mp_obj_type_t lcd_ili9341_type = { - { &mp_type_type }, - .name = MP_QSTR_ILI9341, - .print = lcd_ili9341_print, - .make_new = lcd_ili9341_make_new, - .locals_dict = (mp_obj_t)&lcd_ili9341_locals_dict -}; - -#endif // MICROPY_PY_DISPLAY_LCD_ILI9341 diff --git a/nrf5/modules/display/lcd_ili9341_obj.h b/nrf5/modules/display/lcd_ili9341_obj.h deleted file mode 100644 index 097b7eb69..000000000 --- a/nrf5/modules/display/lcd_ili9341_obj.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef LCD_ILI9341_H__ -#define LCD_ILI9341_H__ - -#include <py/obj.h> - -extern const mp_obj_type_t lcd_ili9341_type; - -#endif // LCD_ILI9341_H__ - diff --git a/nrf5/modules/display/lcd_ls0xxb7dxxx_driver.c b/nrf5/modules/display/lcd_ls0xxb7dxxx_driver.c deleted file mode 100644 index 686a62668..000000000 --- a/nrf5/modules/display/lcd_ls0xxb7dxxx_driver.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdbool.h> - -#include "py/mphal.h" - -#include "lcd_ls0xxb7dxxx_driver.h" -#include "hal_spi.h" -#include "hal_time.h" - -#include "framebuffer.h" - -#if MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX - -static pin_obj_t * mp_cs_pin; -static pin_obj_t * mp_disp_pin; -static pin_obj_t * mp_extcomin_pin; -static pin_obj_t * mp_extmode_pin; -static pin_obj_t * mp_power_control_pin; -static pin_obj_t * mp_power_charge_pin; -static NRF_SPI_Type * mp_instance; - - -static void raw_write(uint8_t value) -{ - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); -} - -void driver_ls0xxb7dxxx_init(NRF_SPI_Type * p_instance, - pin_obj_t * p_cs_pin, - pin_obj_t * p_disp_pin, - pin_obj_t * p_ext_com_in_pin, - pin_obj_t * p_ext_mode_pin, - pin_obj_t * p_power_control_pin, - pin_obj_t * p_power_charge_pin) { - mp_instance = p_instance; - mp_cs_pin = p_cs_pin; - mp_disp_pin = p_disp_pin; - mp_extcomin_pin = p_ext_com_in_pin; - mp_extmode_pin = p_ext_mode_pin; - mp_power_control_pin = p_power_control_pin; - mp_power_charge_pin = p_power_charge_pin; - - mp_hal_pin_high(mp_extcomin_pin); - mp_hal_pin_low(mp_disp_pin); - mp_hal_pin_low(mp_cs_pin); - mp_hal_pin_low(mp_extmode_pin); - mp_hal_pin_low(mp_power_charge_pin); - mp_hal_pin_low(mp_power_control_pin); - - // power on display - mp_hal_pin_high(mp_power_charge_pin); - mp_hal_pin_high(mp_power_control_pin); - - // display on - mp_hal_pin_high(mp_disp_pin); - - mp_hal_pin_low(mp_extcomin_pin); - -} - -void driver_ls0xxb7dxxx_clear(uint16_t color) -{ - mp_hal_pin_high(mp_cs_pin); - raw_write(0x04); // clear command - raw_write(0x00); - mp_hal_pin_low(mp_cs_pin); -} - -void driver_ls0xxb7dxxx_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len) { - // update single line - 0x01 <line_num> <50bytes data> 0x00 0x00 - // update multi line - 0x01 <line_num> <50bytes data> 0x00 [<line_num> <50bytes data> 0x00] 0x00 - - mp_hal_pin_high(mp_cs_pin); - - mp_hal_delay_us(3); - - raw_write(0x01); - - raw_write(line); - for (uint8_t i = 0; i < 50; i++) - { - uint8_t byte = (uint8_t)((uint8_t *)p_bytes)[i]; - raw_write(~byte); - } - raw_write(0x00); - - raw_write(0x00); - - mp_hal_delay_us(1); - - mp_hal_pin_low(mp_cs_pin); -} - -#endif diff --git a/nrf5/modules/display/lcd_ls0xxb7dxxx_driver.h b/nrf5/modules/display/lcd_ls0xxb7dxxx_driver.h deleted file mode 100644 index 380fba0b2..000000000 --- a/nrf5/modules/display/lcd_ls0xxb7dxxx_driver.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef LCD_LS0XXB7DXXX_DRIVER_H__ -#define LCD_LS0XXB7DXXX_DRIVER_H__ - -#include "py/mphal.h" - -#include "hal_spi.h" -#include "framebuffer.h" - -void driver_ls0xxb7dxxx_init(NRF_SPI_Type * p_instance, - pin_obj_t * p_cs_pin, - pin_obj_t * p_disp_pin, - pin_obj_t * p_ext_com_in_pin, - pin_obj_t * p_ext_mode_pin, - pin_obj_t * p_power_control_pin, - pin_obj_t * p_power_charge_pin); - -void driver_ls0xxb7dxxx_clear(uint16_t color); - -void driver_ls0xxb7dxxx_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len); - -#endif // LCD_LS0XXB7DXXX_DRIVER_H__ diff --git a/nrf5/modules/display/lcd_ls0xxb7dxxx_obj.c b/nrf5/modules/display/lcd_ls0xxb7dxxx_obj.c deleted file mode 100644 index afbc1f620..000000000 --- a/nrf5/modules/display/lcd_ls0xxb7dxxx_obj.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "genhdr/pins.h" - -#include "lcd_ls0xxb7dxxx_driver.h" - -#if MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX - -/// \moduleref display -/// \class LS0XXB7DXXX - LS0XXB7DXXX TFT LCD display driver. - -#include "moddisplay.h" -#include "framebuffer.h" -#include "pin.h" -#include "spi.h" - -typedef struct _lcd_ls0xxb7dxxx_obj_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; - framebuffer_t * framebuffer; - machine_hard_spi_obj_t *spi; - pin_obj_t * pin_cs; - pin_obj_t * pin_disp; - pin_obj_t * pin_extcomin; - pin_obj_t * pin_extmode; - pin_obj_t * pin_power_control; - pin_obj_t * pin_power_charge; -} lcd_ls0xxb7dxxx_obj_t; - -#define LCD_LS0XXB7DXXX_COLOR_BLACK 0 -#define LCD_LS0XXB7DXXX_COLOR_WHITE 1 - -static void set_pixel(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color) { - lcd_ls0xxb7dxxx_obj_t *self = (lcd_ls0xxb7dxxx_obj_t *)p_display; - - if (color == LCD_LS0XXB7DXXX_COLOR_BLACK) { - framebuffer_pixel_set(self->framebuffer, x, y); - } else { - framebuffer_pixel_clear(self->framebuffer, x, y); - } -} - -/// \method __str__() -/// Return a string describing the LS0XXB7DXXX object. -STATIC void lcd_ls0xxb7dxxx_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - lcd_ls0xxb7dxxx_obj_t *self = o; - - mp_printf(print, "LS0XXB7DXXX(SPI(mosi=(port=%u, pin=%u), clk=(port=%u, pin=%u)),\n", - self->spi->pyb->spi->init.mosi_pin->port, - self->spi->pyb->spi->init.mosi_pin->pin, - self->spi->pyb->spi->init.clk_pin->port, - self->spi->pyb->spi->init.clk_pin->pin); - - mp_printf(print, " cs=(port=%u, pin=%u), disp=(port=%u, pin=%u), extcomin=(port=%u, pin=%u),\n", - self->pin_cs->port, - self->pin_cs->pin, - self->pin_disp->port, - self->pin_disp->pin, - self->pin_extcomin->port, - self->pin_extcomin->pin); - mp_printf(print, " extmode=(port=%u, pin=%u), power_control=(port=%u, pin=%u), power_charge=(port=%u, pin=%u),\n", - self->pin_extmode->port, - self->pin_extmode->pin, - self->pin_power_control->port, - self->pin_power_control->pin, - self->pin_power_charge->port, - self->pin_power_charge->pin); - - mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n", - self->framebuffer->screen_width, - self->framebuffer->screen_height, - self->framebuffer->line_orientation, - self->framebuffer->fb_stride, - self->framebuffer->fb_dirty_stride); -} - -// for make_new -enum { - ARG_NEW_WIDTH, - ARG_NEW_HEIGHT, - ARG_NEW_SPI, - ARG_NEW_CS, - ARG_NEW_DISP, - ARG_NEW_EXTCOMIN, - ARG_NEW_EXTMODE, - ARG_NEW_POWER_CONTROL, - ARG_NEW_POWER_CHARGE -}; - -/* - -Example for nrf52840 / pca10056: - -from machine import Pin, SPI -from display import LS0XXB7DXXX -import draw -cs = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP) -disp = Pin("B4", mode=Pin.OUT, pull=Pin.PULL_UP) -extcomin = Pin("A28", mode=Pin.OUT, pull=Pin.PULL_UP) -extmode = Pin("B5", mode=Pin.OUT, pull=Pin.PULL_UP) -power_control = Pin("A29", mode=Pin.OUT, pull=Pin.PULL_UP) -power_charge = Pin("A30", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=2000000, firstbit=SPI.LSB) -d = LS0XXB7DXXX(400, 240, spi, cs, disp, extcomin, extmode, power_control, power_charge) -draw.text(d, "Hello World!", 32, 32) -d.show() - -*/ -STATIC mp_obj_t lcd_ls0xxb7dxxx_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - static const mp_arg_t allowed_args[] = { - { ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_SPI, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_DISP, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_EXTCOMIN, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_EXTMODE, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_POWER_CONTROL, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_POWER_CHARGE, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - lcd_ls0xxb7dxxx_obj_t *s = m_new_obj_with_finaliser(lcd_ls0xxb7dxxx_obj_t); - s->base.type = type; - s->draw_callbacks.pixel_set = set_pixel; - - mp_int_t width; - mp_int_t height; - - if (args[ARG_NEW_WIDTH].u_int > 0) { - width = args[ARG_NEW_WIDTH].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display width not set")); - } - - if (args[ARG_NEW_HEIGHT].u_int > 0) { - height = args[ARG_NEW_HEIGHT].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display height not set")); - } - - if (args[ARG_NEW_SPI].u_obj != MP_OBJ_NULL) { - s->spi = args[ARG_NEW_SPI].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display SPI not set")); - } - - if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) { - s->pin_cs = args[ARG_NEW_CS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display CS Pin not set")); - } - - if (args[ARG_NEW_DISP].u_obj != MP_OBJ_NULL) { - s->pin_disp = args[ARG_NEW_DISP].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Disp Pin not set")); - } - - if (args[ARG_NEW_EXTCOMIN].u_obj != MP_OBJ_NULL) { - s->pin_extcomin = args[ARG_NEW_EXTCOMIN].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display ExtComIn Pin not set")); - } - - if (args[ARG_NEW_EXTMODE].u_obj != MP_OBJ_NULL) { - s->pin_extmode = args[ARG_NEW_EXTMODE].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display ExtMode Pin not set")); - } - - if (args[ARG_NEW_POWER_CONTROL].u_obj != MP_OBJ_NULL) { - s->pin_power_control = args[ARG_NEW_POWER_CONTROL].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display PowerControl Pin not set")); - } - - if (args[ARG_NEW_POWER_CHARGE].u_obj != MP_OBJ_NULL) { - s->pin_power_charge = args[ARG_NEW_POWER_CHARGE].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display PowerCharge Pin not set")); - } - - framebuffer_init_t init_conf = { - .width = width, - .height = height, - .line_orientation = FRAMEBUFFER_LINE_DIR_HORIZONTAL, - .double_buffer = false - }; - - s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t)); - - framebuffer_init(s->framebuffer, &init_conf); - - driver_ls0xxb7dxxx_init(s->spi->pyb->spi->instance, - s->pin_cs, - s->pin_disp, - s->pin_extcomin, - s->pin_extmode, - s->pin_power_control, - s->pin_power_charge); - - // Default to black background - driver_ls0xxb7dxxx_clear(0x00); - - framebuffer_clear(s->framebuffer); - - return MP_OBJ_FROM_PTR(s); -} - -// text - -/// \method fill(color) -/// Fill framebuffer with the color defined as argument. -STATIC mp_obj_t lcd_ls0xxb7dxxx_fill(mp_obj_t self_in, mp_obj_t color) { - lcd_ls0xxb7dxxx_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (color == MP_OBJ_NEW_SMALL_INT(LCD_LS0XXB7DXXX_COLOR_BLACK)) { - framebuffer_fill(self->framebuffer); - } else { - framebuffer_clear(self->framebuffer); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lcd_ls0xxb7dxxx_fill_obj, lcd_ls0xxb7dxxx_fill); - -static void render(framebuffer_t * p_framebuffer) { - for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) { - if (p_framebuffer->fb_dirty[i].byte != 0) { - for (uint16_t b = 0; b < 8; b++) { - if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1)) { - uint16_t line_num = (i * 8) + b; - driver_ls0xxb7dxxx_update_line(line_num, - &p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride], - p_framebuffer->fb_stride); - } - } - - p_framebuffer->fb_dirty[i].byte = 0x00; - } - } -} - -/// \method show() -/// Display content in framebuffer. -STATIC mp_obj_t lcd_ls0xxb7dxxx_show(size_t n_args, const mp_obj_t *args) { - lcd_ls0xxb7dxxx_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - render(self->framebuffer); - framebuffer_flip(self->framebuffer); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ls0xxb7dxxx_show_obj, 1, 2, lcd_ls0xxb7dxxx_show); - -/// \method refresh([num_of_refresh]) -/// Refresh content in framebuffer. -/// -/// - With no argument, 1 refresh will be done. -/// - With `num_of_refresh` given, The whole framebuffer will be considered -/// dirty and will be refreshed the given number of times. -STATIC mp_obj_t lcd_ls0xxb7dxxx_refresh(mp_obj_t self_in) { - lcd_ls0xxb7dxxx_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_ls0xxb7dxxx_refresh_obj, lcd_ls0xxb7dxxx_refresh); - -/// \method pixel(x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color of the pixel in framebuffer will be returend. -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t lcd_ls0xxb7dxxx_pixel(size_t n_args, const mp_obj_t *args) { - lcd_ls0xxb7dxxx_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_int_t x = mp_obj_get_int(args[1]); - mp_int_t y = mp_obj_get_int(args[2]); - mp_int_t color = mp_obj_get_int(args[3]); - - set_pixel(self, x, y, color); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ls0xxb7dxxx_pixel_obj, 4, 4, lcd_ls0xxb7dxxx_pixel); - -/// \method pixel(text, x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color will be the opposite of background (fill color). -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t lcd_ls0xxb7dxxx_text(size_t n_args, const mp_obj_t *args) { - lcd_ls0xxb7dxxx_obj_t *self = MP_OBJ_TO_PTR(args[0]); - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color; - if (n_args >= 4) { - color = mp_obj_get_int(args[3]); - } - - //display_print_string(self->framebuffer, x, y, str); - - (void)x; - (void)y; - (void)self; - (void)str; - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ls0xxb7dxxx_text_obj, 4, 5, lcd_ls0xxb7dxxx_text); - -STATIC mp_obj_t lcd_ls0xxb7dxxx_del(mp_obj_t self_in) { - lcd_ls0xxb7dxxx_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_ls0xxb7dxxx_del_obj, lcd_ls0xxb7dxxx_del); - -STATIC const mp_map_elem_t lcd_ls0xxb7dxxx_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)(&lcd_ls0xxb7dxxx_del_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_fill), (mp_obj_t)(&lcd_ls0xxb7dxxx_fill_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)(&lcd_ls0xxb7dxxx_show_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)(&lcd_ls0xxb7dxxx_text_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)(&lcd_ls0xxb7dxxx_pixel_obj) }, -#if 0 - { MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&lcd_ls0xxb7dxxx_bitmap_obj) }, -#endif - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(LCD_LS0XXB7DXXX_COLOR_BLACK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(LCD_LS0XXB7DXXX_COLOR_WHITE) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) }, -}; - -STATIC MP_DEFINE_CONST_DICT(lcd_ls0xxb7dxxx_locals_dict, lcd_ls0xxb7dxxx_locals_dict_table); - -const mp_obj_type_t lcd_ls0xxb7dxxx_type = { - { &mp_type_type }, - .name = MP_QSTR_LS0XXB7DXXX, - .print = lcd_ls0xxb7dxxx_print, - .make_new = lcd_ls0xxb7dxxx_make_new, - .locals_dict = (mp_obj_t)&lcd_ls0xxb7dxxx_locals_dict -}; - -#endif // MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX diff --git a/nrf5/modules/display/lcd_ls0xxb7dxxx_obj.h b/nrf5/modules/display/lcd_ls0xxb7dxxx_obj.h deleted file mode 100644 index a1f2b3f83..000000000 --- a/nrf5/modules/display/lcd_ls0xxb7dxxx_obj.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef LCD_LS0XXB7DXXX_H__ -#define LCD_LS0XXB7DXXX_H__ - -#include <py/obj.h> - -extern const mp_obj_type_t lcd_ls0xxb7dxxx_type; - -#endif // LCD_LS0XXB7DXXX_H__ - diff --git a/nrf5/modules/display/lcd_ssd1289_driver.c b/nrf5/modules/display/lcd_ssd1289_driver.c deleted file mode 100644 index db2bae803..000000000 --- a/nrf5/modules/display/lcd_ssd1289_driver.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdbool.h> - -#include "py/mphal.h" - -#include "lcd_ssd1289_driver.h" -#include "hal_time.h" - -#include "framebuffer.h" - -#if MICROPY_PY_DISPLAY_LCD_SSD1289 - -static pin_obj_t * mp_cs_pin; -static pin_obj_t * mp_rs_pin; -static pin_obj_t * mp_wr_pin; -static pin_obj_t * mp_reset_pin; -static pin_obj_t * mp_d0_pin; -static pin_obj_t * mp_d1_pin; -static pin_obj_t * mp_d2_pin; -static pin_obj_t * mp_d3_pin; -static pin_obj_t * mp_d4_pin; -static pin_obj_t * mp_d5_pin; -static pin_obj_t * mp_d6_pin; -static pin_obj_t * mp_d7_pin; - -static void data_port_write(uint8_t byte) { - mp_hal_pin_write(mp_d0_pin, (byte >> 0) & 0x1); - mp_hal_pin_write(mp_d1_pin, (byte >> 1) & 0x1); - mp_hal_pin_write(mp_d2_pin, (byte >> 2) & 0x1); - mp_hal_pin_write(mp_d3_pin, (byte >> 3) & 0x1); - mp_hal_pin_write(mp_d4_pin, (byte >> 4) & 0x1); - mp_hal_pin_write(mp_d5_pin, (byte >> 5) & 0x1); - mp_hal_pin_write(mp_d6_pin, (byte >> 6) & 0x1); - mp_hal_pin_write(mp_d7_pin, (byte >> 7) & 0x1); - mp_hal_pin_low(mp_wr_pin); - mp_hal_delay_us(20); - mp_hal_pin_high(mp_wr_pin); -} - -static void cmd_write(uint8_t cmd) { - mp_hal_pin_low(mp_rs_pin); - mp_hal_delay_us(20); - data_port_write(0x00); - mp_hal_delay_us(20); - data_port_write(cmd); -} - -static void data_write(uint16_t value) { - mp_hal_pin_high(mp_rs_pin); - - uint8_t high_byte = (uint8_t)(value >> 8); - uint8_t low_byte = (uint8_t)(value & 0xFF); - mp_hal_delay_us(20); - data_port_write(high_byte); - mp_hal_delay_us(20); - data_port_write(low_byte); -} - -#define LCD_WRITE(a, b) { \ - cmd_write(a); \ - data_write(b); } - -void driver_ssd1289_init(pin_obj_t * p_cs_pin, - pin_obj_t * p_rs_pin, - pin_obj_t * p_wr_pin, - pin_obj_t * p_reset_pin, - pin_obj_t * p_d0_pin, - pin_obj_t * p_d1_pin, - pin_obj_t * p_d2_pin, - pin_obj_t * p_d3_pin, - pin_obj_t * p_d4_pin, - pin_obj_t * p_d5_pin, - pin_obj_t * p_d6_pin, - pin_obj_t * p_d7_pin) { - - mp_cs_pin = p_cs_pin; - mp_rs_pin = p_rs_pin; - mp_wr_pin = p_wr_pin; - mp_reset_pin = p_reset_pin; - mp_d0_pin = p_d0_pin; - mp_d1_pin = p_d1_pin; - mp_d2_pin = p_d2_pin; - mp_d3_pin = p_d3_pin; - mp_d4_pin = p_d4_pin; - mp_d5_pin = p_d5_pin; - mp_d6_pin = p_d6_pin; - mp_d7_pin = p_d7_pin; - - mp_hal_pin_low(mp_d0_pin); - mp_hal_pin_low(mp_d1_pin); - mp_hal_pin_low(mp_d2_pin); - mp_hal_pin_low(mp_d3_pin); - mp_hal_pin_low(mp_d4_pin); - mp_hal_pin_low(mp_d5_pin); - mp_hal_pin_low(mp_d6_pin); - mp_hal_pin_low(mp_d7_pin); - - mp_hal_pin_low(mp_rs_pin); - mp_hal_pin_low(mp_wr_pin); - - mp_hal_pin_low(mp_cs_pin); - - mp_hal_pin_high(mp_reset_pin); - mp_hal_delay_ms(20); - mp_hal_pin_high(mp_reset_pin); - - LCD_WRITE(0x00,0x0001); - LCD_WRITE(0x03,0xA8A4); - LCD_WRITE(0x0C,0x0000); - LCD_WRITE(0x0D,0x080C); - LCD_WRITE(0x0E,0x2B00); - LCD_WRITE(0x1E,0x00B7); - LCD_WRITE(0x01,0x2B3F); - LCD_WRITE(0x02,0x0600); - LCD_WRITE(0x10,0x0000); - LCD_WRITE(0x11,0x6070); - LCD_WRITE(0x05,0x0000); - LCD_WRITE(0x06,0x0000); - LCD_WRITE(0x16,0xEF1C); - LCD_WRITE(0x17,0x0003); - LCD_WRITE(0x07,0x0233); - LCD_WRITE(0x0B,0x0000); - LCD_WRITE(0x0F,0x0000); - LCD_WRITE(0x41,0x0000); - LCD_WRITE(0x42,0x0000); - LCD_WRITE(0x48,0x0000); - LCD_WRITE(0x49,0x013F); - LCD_WRITE(0x4A,0x0000); - LCD_WRITE(0x4B,0x0000); - LCD_WRITE(0x44,0xEF00); - LCD_WRITE(0x45,0x0000); - LCD_WRITE(0x46,0x013F); - LCD_WRITE(0x30,0x0707); - LCD_WRITE(0x31,0x0204); - LCD_WRITE(0x32,0x0204); - LCD_WRITE(0x33,0x0502); - LCD_WRITE(0x34,0x0507); - LCD_WRITE(0x35,0x0204); - LCD_WRITE(0x36,0x0204); - LCD_WRITE(0x37,0x0502); - LCD_WRITE(0x3A,0x0302); - LCD_WRITE(0x3B,0x0302); - LCD_WRITE(0x23,0x0000); - LCD_WRITE(0x24,0x0000); - LCD_WRITE(0x25,0x8000); - LCD_WRITE(0x4f,0x0000); - LCD_WRITE(0x4e,0x0000); - cmd_write(0x22); - - mp_hal_pin_high(mp_cs_pin); -} - -static void set_xy(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { - LCD_WRITE(0x44, (y1 << 8) + y0); - LCD_WRITE(0x45, 319 - x1); - LCD_WRITE(0x46, 319 - x0); - LCD_WRITE(0x4e, y0); - LCD_WRITE(0x4f, 319 - x1); - cmd_write(0x22); -} - -void driver_ssd1289_clear(uint16_t color) { - uint16_t x; - uint16_t y; - uint16_t lcd_x_size = 240; - uint16_t lcd_y_size = 320; - - mp_hal_pin_low(mp_cs_pin); - - set_xy(0, 0, lcd_y_size - 1, lcd_x_size - 1); - - for (x = 0; x < lcd_x_size; x++) { - for (y = 0; y < lcd_y_size; y++) { - data_write(color); - } - } - - mp_hal_pin_high(mp_cs_pin); -} - -void driver_ssd1289_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len) { - set_xy(0, line, 319, line); - - mp_hal_pin_low(mp_cs_pin); - - for (uint8_t i = 0; i < len; i++) { - uint8_t byte = (uint8_t)((uint8_t *)p_bytes)[i]; - for (uint8_t pixel_pos = 0; pixel_pos < 8; pixel_pos++) { - if (((byte >> pixel_pos) & 0x1) == 0x0) { - data_write(0x0000); - } else { - data_write(0xFFFF); - } - } - } - - mp_hal_pin_high(mp_cs_pin); -} - -#endif // MICROPY_PY_DISPLAY_LCD_SSD1289 diff --git a/nrf5/modules/display/lcd_ssd1289_driver.h b/nrf5/modules/display/lcd_ssd1289_driver.h deleted file mode 100644 index 58b36618d..000000000 --- a/nrf5/modules/display/lcd_ssd1289_driver.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef LCD_SSD1289_DRIVER_H__ -#define LCD_SSD1289_DRIVER_H__ - -#include "py/mphal.h" - -#include "framebuffer.h" - -void driver_ssd1289_init(pin_obj_t * p_cs_pin, - pin_obj_t * p_rs_pin, - pin_obj_t * p_wr_pin, - pin_obj_t * p_reset_pin, - pin_obj_t * p_d0_pin, - pin_obj_t * p_d1_pin, - pin_obj_t * p_d2_pin, - pin_obj_t * p_d3_pin, - pin_obj_t * p_d4_pin, - pin_obj_t * p_d5_pin, - pin_obj_t * p_d6_pin, - pin_obj_t * p_d7_pin); - - -void driver_ssd1289_clear(uint16_t color); - -void driver_ssd1289_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len); - -#endif // LCD_SSD1289_DRIVER_H__ diff --git a/nrf5/modules/display/lcd_ssd1289_obj.c b/nrf5/modules/display/lcd_ssd1289_obj.c deleted file mode 100644 index 24382ab6f..000000000 --- a/nrf5/modules/display/lcd_ssd1289_obj.c +++ /dev/null @@ -1,516 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "genhdr/pins.h" - -#include "lcd_ssd1289_driver.h" - -#if MICROPY_PY_DISPLAY_LCD_SSD1289 - -/// \moduleref display -/// \class SSD1289 - SSD1289 TFT LCD display driver. - -#include "moddisplay.h" -#include "framebuffer.h" -#include "pin.h" - -typedef struct _lcd_ssd1289_obj_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; - framebuffer_t * framebuffer; - pin_obj_t * pin_cs; - pin_obj_t * pin_rs; - pin_obj_t * pin_wr; - pin_obj_t * pin_reset; - pin_obj_t * pin_d0; - pin_obj_t * pin_d1; - pin_obj_t * pin_d2; - pin_obj_t * pin_d3; - pin_obj_t * pin_d4; - pin_obj_t * pin_d5; - pin_obj_t * pin_d6; - pin_obj_t * pin_d7; -} lcd_ssd1289_obj_t; - -#define LCD_SSD1289_COLOR_BLACK 0 -#define LCD_SSD1289_COLOR_WHITE 1 - -static void set_pixel(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color) { - lcd_ssd1289_obj_t *self = (lcd_ssd1289_obj_t *)p_display; - - if (color == LCD_SSD1289_COLOR_BLACK) { - framebuffer_pixel_clear(self->framebuffer, x, y); - } else { - framebuffer_pixel_set(self->framebuffer, x, y); - } -} - -/// \method __str__() -/// Return a string describing the SSD1289 object. -STATIC void lcd_ssd1289_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - lcd_ssd1289_obj_t *self = o; - - mp_printf(print, "SSD1289(cs=(port=%u, pin=%u), rs=(port=%u, pin=%u),\n", - self->pin_cs->port, - self->pin_cs->pin, - self->pin_rs->port, - self->pin_rs->pin); - - mp_printf(print, " wr=(port=%u, pin=%u), reset=(port=%u, pin=%u),\n", - self->pin_wr->port, - self->pin_wr->pin, - self->pin_reset->port, - self->pin_reset->pin); - - mp_printf(print, " d0=(port=%u, pin=%u), d1=(port=%u, pin=%u),\n", - self->pin_d0->port, - self->pin_d0->pin, - self->pin_d1->port, - self->pin_d1->pin); - - mp_printf(print, " d2=(port=%u, pin=%u), d3=(port=%u, pin=%u),\n", - self->pin_d2->port, - self->pin_d2->pin, - self->pin_d3->port, - self->pin_d3->pin); - - mp_printf(print, " d4=(port=%u, pin=%u), d5=(port=%u, pin=%u),\n", - self->pin_d4->port, - self->pin_d4->pin, - self->pin_d5->port, - self->pin_d5->pin); - - mp_printf(print, " d6=(port=%u, pin=%u), d7=(port=%u, pin=%u),\n", - self->pin_d6->port, - self->pin_d6->pin, - self->pin_d7->port, - self->pin_d7->pin); - - - mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n", - self->framebuffer->screen_width, - self->framebuffer->screen_height, - self->framebuffer->line_orientation, - self->framebuffer->fb_stride, - self->framebuffer->fb_dirty_stride); -} - -// for make_new -enum { - ARG_NEW_WIDTH, - ARG_NEW_HEIGHT, - ARG_NEW_CS, - ARG_NEW_RS, - ARG_NEW_WR, - ARG_NEW_RESET, - ARG_NEW_D0, - ARG_NEW_D1, - ARG_NEW_D2, - ARG_NEW_D3, - ARG_NEW_D4, - ARG_NEW_D5, - ARG_NEW_D6, - ARG_NEW_D7, - -}; - -/* - -Example for nrf51822 / pca10028: - -from machine import Pin -from display import SSD1289 -import draw -cs = Pin("A1", mode=Pin.OUT, pull=Pin.PULL_UP) -rs = Pin("A2", mode=Pin.OUT, pull=Pin.PULL_UP) -wr = Pin("A3", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A4", mode=Pin.OUT, pull=Pin.PULL_UP) - -d0 = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -d1 = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -d2 = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) -d3 = Pin("A15", mode=Pin.OUT, pull=Pin.PULL_UP) -d4 = Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP) -d5 = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP) -d6 = Pin("A18", mode=Pin.OUT, pull=Pin.PULL_UP) -d7 = Pin("A19", mode=Pin.OUT, pull=Pin.PULL_UP) - -d = SSD1289(320, 240, cs, rs, wr, reset, d0, d1, d2, d3, d4, d5, d6, d7) -draw.text(d, "Hello World!", 32, 32) -d.show() - -Example for nrf52832 / pca10040: - -from machine import Pin -from display import SSD1289 -import draw -cs = Pin("A3", mode=Pin.OUT, pull=Pin.PULL_UP) -rs = Pin("A4", mode=Pin.OUT, pull=Pin.PULL_UP) -wr = Pin("A28", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A29", mode=Pin.OUT, pull=Pin.PULL_UP) - -d0 = Pin("A11", mode=Pin.OUT, pull=Pin.PULL_UP) -d1 = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -d2 = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -d3 = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) -d4 = Pin("A15", mode=Pin.OUT, pull=Pin.PULL_UP) -d5 = Pin("A16", mode=Pin.OUT, pull=Pin.PULL_UP) -d6 = Pin("A17", mode=Pin.OUT, pull=Pin.PULL_UP) -d7 = Pin("A18", mode=Pin.OUT, pull=Pin.PULL_UP) - -d = SSD1289(240, 320, cs, rs, wr, reset, d0, d1, d2, d3, d4, d5, d6, d7) -draw.text(d, "Hello World!", 32, 32) -d.show() - -Example for nrf52840 / pca10056: - -from machine import Pin -from display import SSD1289 -import draw -cs = Pin("A3", mode=Pin.OUT, pull=Pin.PULL_UP) -rs = Pin("A4", mode=Pin.OUT, pull=Pin.PULL_UP) -wr = Pin("A28", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A29", mode=Pin.OUT, pull=Pin.PULL_UP) - -d0 = Pin("B1", mode=Pin.OUT, pull=Pin.PULL_UP) -d1 = Pin("B2", mode=Pin.OUT, pull=Pin.PULL_UP) -d2 = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP) -d3 = Pin("B4", mode=Pin.OUT, pull=Pin.PULL_UP) -d4 = Pin("B5", mode=Pin.OUT, pull=Pin.PULL_UP) -d5 = Pin("B6", mode=Pin.OUT, pull=Pin.PULL_UP) -d6 = Pin("B7", mode=Pin.OUT, pull=Pin.PULL_UP) -d7 = Pin("B8", mode=Pin.OUT, pull=Pin.PULL_UP) - -d = SSD1289(320, 240, cs, rs, wr, reset, d0, d1, d2, d3, d4, d5, d6, d7) -draw.text(d, "Hello World!", 32, 32) -d.show() - -*/ -STATIC mp_obj_t lcd_ssd1289_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - static const mp_arg_t allowed_args[] = { - { ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_RS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_WR, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_RESET, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D0, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D1, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D2, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D3, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D4, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D5, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D6, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_D7, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - lcd_ssd1289_obj_t *s = m_new_obj_with_finaliser(lcd_ssd1289_obj_t); - s->base.type = type; - s->draw_callbacks.pixel_set = set_pixel; - - mp_int_t width; - mp_int_t height; - - if (args[ARG_NEW_WIDTH].u_int > 0) { - width = args[ARG_NEW_WIDTH].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display width not set")); - } - - if (args[ARG_NEW_HEIGHT].u_int > 0) { - height = args[ARG_NEW_HEIGHT].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display height not set")); - } - - if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) { - s->pin_cs = args[ARG_NEW_CS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display CS Pin not set")); - } - - if (args[ARG_NEW_RS].u_obj != MP_OBJ_NULL) { - s->pin_rs = args[ARG_NEW_RS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display RS Pin not set")); - } - - if (args[ARG_NEW_WR].u_obj != MP_OBJ_NULL) { - s->pin_wr = args[ARG_NEW_WR].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display WR Pin not set")); - } - - if (args[ARG_NEW_RESET].u_obj != MP_OBJ_NULL) { - s->pin_reset = args[ARG_NEW_RESET].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Reset Pin not set")); - } - - if (args[ARG_NEW_D0].u_obj != MP_OBJ_NULL) { - s->pin_d0 = args[ARG_NEW_D0].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 0 Pin not set")); - } - - if (args[ARG_NEW_D1].u_obj != MP_OBJ_NULL) { - s->pin_d1 = args[ARG_NEW_D1].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 1 Pin not set")); - } - - if (args[ARG_NEW_D2].u_obj != MP_OBJ_NULL) { - s->pin_d2 = args[ARG_NEW_D2].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 2 Pin not set")); - } - - if (args[ARG_NEW_D3].u_obj != MP_OBJ_NULL) { - s->pin_d3 = args[ARG_NEW_D3].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 3 Pin not set")); - } - - if (args[ARG_NEW_D4].u_obj != MP_OBJ_NULL) { - s->pin_d4 = args[ARG_NEW_D4].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 4 Pin not set")); - } - - if (args[ARG_NEW_D5].u_obj != MP_OBJ_NULL) { - s->pin_d5 = args[ARG_NEW_D5].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 5 Pin not set")); - } - - if (args[ARG_NEW_D6].u_obj != MP_OBJ_NULL) { - s->pin_d6 = args[ARG_NEW_D6].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 6 Pin not set")); - } - - if (args[ARG_NEW_D7].u_obj != MP_OBJ_NULL) { - s->pin_d7 = args[ARG_NEW_D7].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Data 7 Pin not set")); - } - - framebuffer_init_t init_conf = { - .width = width, - .height = height, - .line_orientation = FRAMEBUFFER_LINE_DIR_HORIZONTAL, - .double_buffer = false - }; - - s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t)); - - framebuffer_init(s->framebuffer, &init_conf); - - driver_ssd1289_init(s->pin_cs, - s->pin_rs, - s->pin_wr, - s->pin_reset, - s->pin_d0, - s->pin_d1, - s->pin_d2, - s->pin_d3, - s->pin_d4, - s->pin_d5, - s->pin_d6, - s->pin_d7); - - // Default to black background - driver_ssd1289_clear(0x00FF); - - framebuffer_clear(s->framebuffer); - - return MP_OBJ_FROM_PTR(s); -} - -// text - -/// \method fill(color) -/// Fill framebuffer with the color defined as argument. -STATIC mp_obj_t lcd_ssd1289_fill(mp_obj_t self_in, mp_obj_t color) { - lcd_ssd1289_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (color == MP_OBJ_NEW_SMALL_INT(LCD_SSD1289_COLOR_BLACK)) { - framebuffer_clear(self->framebuffer); - } else { - framebuffer_fill(self->framebuffer); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(lcd_ssd1289_fill_obj, lcd_ssd1289_fill); - -static void render(framebuffer_t * p_framebuffer) { - for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) { - if (p_framebuffer->fb_dirty[i].byte != 0) { - for (uint16_t b = 0; b < 8; b++) { - if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1)) { - uint16_t line_num = (i * 8) + b; - driver_ssd1289_update_line(line_num, - &p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride], - p_framebuffer->fb_stride); - } - } - - p_framebuffer->fb_dirty[i].byte = 0x00; - } - } -} - -/// \method show() -/// Display content in framebuffer. -STATIC mp_obj_t lcd_ssd1289_show(size_t n_args, const mp_obj_t *args) { - lcd_ssd1289_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - render(self->framebuffer); - framebuffer_flip(self->framebuffer); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ssd1289_show_obj, 1, 2, lcd_ssd1289_show); - -/// \method refresh([num_of_refresh]) -/// Refresh content in framebuffer. -/// -/// - With no argument, 1 refresh will be done. -/// - With `num_of_refresh` given, The whole framebuffer will be considered -/// dirty and will be refreshed the given number of times. -STATIC mp_obj_t lcd_ssd1289_refresh(mp_obj_t self_in) { - lcd_ssd1289_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_ssd1289_refresh_obj, lcd_ssd1289_refresh); - -/// \method pixel(x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color of the pixel in framebuffer will be returend. -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t lcd_ssd1289_pixel(size_t n_args, const mp_obj_t *args) { - lcd_ssd1289_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_int_t x = mp_obj_get_int(args[1]); - mp_int_t y = mp_obj_get_int(args[2]); - mp_int_t color = mp_obj_get_int(args[3]); - - set_pixel(self, x, y, color); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ssd1289_pixel_obj, 4, 4, lcd_ssd1289_pixel); - -/// \method pixel(text, x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color will be the opposite of background (fill color). -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t lcd_ssd1289_text(size_t n_args, const mp_obj_t *args) { - lcd_ssd1289_obj_t *self = MP_OBJ_TO_PTR(args[0]); - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color; - if (n_args >= 4) { - color = mp_obj_get_int(args[3]); - } - - //display_print_string(self->framebuffer, x, y, str); - - (void)x; - (void)y; - (void)self; - (void)str; - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lcd_ssd1289_text_obj, 4, 5, lcd_ssd1289_text); - -STATIC mp_obj_t lcd_ssd1289_del(mp_obj_t self_in) { - lcd_ssd1289_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(lcd_ssd1289_del_obj, lcd_ssd1289_del); - -STATIC const mp_map_elem_t lcd_ssd1289_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)(&lcd_ssd1289_del_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_fill), (mp_obj_t)(&lcd_ssd1289_fill_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)(&lcd_ssd1289_show_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)(&lcd_ssd1289_text_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)(&lcd_ssd1289_pixel_obj) }, -#if 0 - { MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&lcd_ssd1289_bitmap_obj) }, -#endif - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(LCD_SSD1289_COLOR_BLACK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(LCD_SSD1289_COLOR_WHITE) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) }, -}; - -STATIC MP_DEFINE_CONST_DICT(lcd_ssd1289_locals_dict, lcd_ssd1289_locals_dict_table); - -const mp_obj_type_t lcd_ssd1289_type = { - { &mp_type_type }, - .name = MP_QSTR_SSD1289, - .print = lcd_ssd1289_print, - .make_new = lcd_ssd1289_make_new, - .locals_dict = (mp_obj_t)&lcd_ssd1289_locals_dict -}; - -#endif // MICROPY_PY_DISPLAY_LCD_SSD1289 diff --git a/nrf5/modules/display/lcd_ssd1289_obj.h b/nrf5/modules/display/lcd_ssd1289_obj.h deleted file mode 100644 index 7105c110c..000000000 --- a/nrf5/modules/display/lcd_ssd1289_obj.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef LCD_SSD1289_H__ -#define LCD_SSD1289_H__ - -#include <py/obj.h> - -extern const mp_obj_type_t lcd_ssd1289_type; - -#endif // LCD_SSD1289_H__ - diff --git a/nrf5/modules/display/moddisplay.c b/nrf5/modules/display/moddisplay.c deleted file mode 100644 index ca4db0b45..000000000 --- a/nrf5/modules/display/moddisplay.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" - -#if MICROPY_PY_DISPLAY - -#include "epaper_sld00200p_obj.h" -#include "lcd_ili9341_obj.h" -#include "lcd_ls0xxb7dxxx_obj.h" -#include "lcd_ssd1289_obj.h" -#include "oled_ssd1305_obj.h" -#include "oled_ssd1306_obj.h" - -STATIC const mp_map_elem_t mp_module_display_globals_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_display) }, -#if MICROPY_PY_DISPLAY_EPAPER_SLD00200P - { MP_OBJ_NEW_QSTR(MP_QSTR_SLD00200P), (mp_obj_t)&epaper_sld00200p_type }, -#endif -#if MICROPY_PY_DISPLAY_LCD_ILI9341 - { MP_OBJ_NEW_QSTR(MP_QSTR_ILI9341), (mp_obj_t)&lcd_ili9341_type }, -#endif -#if MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX - { MP_OBJ_NEW_QSTR(MP_QSTR_LS0XXB7DXXX), (mp_obj_t)&lcd_ls0xxb7dxxx_type }, -#endif -#if MICROPY_PY_DISPLAY_LCD_SSD1289 - { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1289), (mp_obj_t)&lcd_ssd1289_type }, -#endif -#if MICROPY_PY_DISPLAY_OLED_SSD1305 - { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1305), (mp_obj_t)&oled_ssd1305_type }, -#endif -#if MICROPY_PY_DISPLAY_OLED_SSD1306 - { MP_OBJ_NEW_QSTR(MP_QSTR_SSD1306), (mp_obj_t)&oled_ssd1306_type }, -#endif -}; - - -STATIC MP_DEFINE_CONST_DICT(mp_module_display_globals, mp_module_display_globals_table); - -const mp_obj_module_t mp_module_display = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&mp_module_display_globals, -}; - -#endif // MICROPY_PY_DISPLAY diff --git a/nrf5/modules/display/moddisplay.h b/nrf5/modules/display/moddisplay.h deleted file mode 100644 index 82ff59502..000000000 --- a/nrf5/modules/display/moddisplay.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef MODDISPLAY_H__ -#define MODDISPLAY_H__ - -typedef struct _display_t display_t; - -typedef void (*pixel_set_callback_t)(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color); - -typedef struct _display_draw_callbacks_t { - pixel_set_callback_t pixel_set; -} display_draw_callbacks_t; - -typedef struct _display_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; -} display_t; - -#endif // MODDISPLAY_H__ diff --git a/nrf5/modules/display/oled_ssd1305_driver.c b/nrf5/modules/display/oled_ssd1305_driver.c deleted file mode 100644 index 95fc8f26c..000000000 --- a/nrf5/modules/display/oled_ssd1305_driver.c +++ /dev/null @@ -1,207 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdbool.h> - -#include "py/mphal.h" - -#include "oled_ssd1305_driver.h" -#include "hal_spi.h" -#include "hal_time.h" - -#include "framebuffer.h" - -#if MICROPY_PY_DISPLAY_OLED_SSD1305 - -static pin_obj_t * mp_cs_pin; -static pin_obj_t * mp_dc_pin; -static pin_obj_t * mp_reset_pin; -static NRF_SPI_Type * mp_instance; - - -static void raw_write(uint8_t value) -{ - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); - -} - -static void cmd_write(uint8_t value) -{ - mp_hal_pin_low(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); - - mp_hal_pin_high(mp_cs_pin); -} - -#define SET_CONTRAST (0x81) -#define SET_ENTIRE_ON (0xa4) -#define SET_NORM_INV (0xa6) -#define SET_DISP (0xae) -#define SET_MEM_ADDR (0x20) -#define SET_COL_ADDR (0x21) -#define SET_PAGE_ADDR (0x22) -#define SET_DISP_START_LINE (0x40) -#define SET_SEG_REMAP (0xa0) -#define SET_MUX_RATIO (0xa8) -#define SET_COM_OUT_DIR (0xc0) -#define SET_DISP_OFFSET (0xd3) -#define SET_COM_PIN_CFG (0xda) -#define SET_DISP_CLK_DIV (0xd5) -#define SET_PRECHARGE (0xd9) -#define SET_VCOM_DESEL (0xdb) -#define SET_CHARGE_PUMP (0x8d) - -void driver_ssd1305_init(NRF_SPI_Type * p_instance, pin_obj_t * p_cs_pin, pin_obj_t * p_dc_pin, pin_obj_t * p_reset_pin) -{ - mp_instance = p_instance; - mp_cs_pin = p_cs_pin; - mp_dc_pin = p_dc_pin; - mp_reset_pin = p_reset_pin; - - mp_hal_pin_high(mp_cs_pin); - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_high(mp_reset_pin); - - // power on display - mp_hal_pin_high(mp_reset_pin); - mp_hal_delay_ms(1); - mp_hal_pin_low(mp_reset_pin); - mp_hal_delay_ms(10); - mp_hal_pin_high(mp_reset_pin); - - // Turn off - cmd_write(SET_DISP | 0x00); // off - - // address setting - cmd_write(SET_MEM_ADDR); - cmd_write(0x00); // horizontal - - // resolution and layout - cmd_write(SET_DISP_START_LINE | 0x00); - cmd_write(SET_SEG_REMAP | 0x00); // column addr 127 mapped to SEG0 - cmd_write(SET_MUX_RATIO); - - uint16_t height = 64; // TODO: configurable - cmd_write(height - 1); // height - 1 - cmd_write(SET_COM_OUT_DIR | 0x08); // scan from COM[N] to COM0 - cmd_write(SET_DISP_OFFSET); - cmd_write(0x00); - cmd_write(SET_COM_PIN_CFG); - if (height == 32) { - cmd_write(0x02); - } else { - cmd_write(0x12); - } - // timing and driving scheme - cmd_write(SET_DISP_CLK_DIV); - cmd_write(0x80); - cmd_write(SET_PRECHARGE); - bool external_vcc = false; - if (external_vcc == true) { - cmd_write(0x22); - } else { - cmd_write(0xf1); - } - cmd_write(SET_VCOM_DESEL); - cmd_write(0x30); // 0.83*Vcc - // display - cmd_write(SET_CONTRAST); - cmd_write(0xff); // maximum - cmd_write(SET_ENTIRE_ON); // output follows RAM contents - cmd_write(SET_NORM_INV); // not inverted - // charge pump - cmd_write(SET_CHARGE_PUMP); - if (external_vcc == true) { - cmd_write(0x10); - } else { - cmd_write(0x14); - } - // on - cmd_write(SET_DISP | 0x01); -} - -static void set_col(uint16_t start_col, uint16_t end_col) -{ - cmd_write(SET_COL_ADDR); // column command address - cmd_write(start_col & 0xFF ); - cmd_write(end_col & 0xFF); -} - -static void set_page(uint16_t start_page, uint16_t end_page) -{ - cmd_write(SET_PAGE_ADDR); // page command address - cmd_write(start_page & 0xFF); - cmd_write(end_page & 0xFF); -} - -void driver_ssd1305_clear(uint16_t color) -{ - uint16_t width = 128; - uint16_t height = 64; - - uint16_t x0 = 0; - uint16_t x1 = width - 1; - uint16_t y0 = 0; - uint16_t y1 = height -1; - - if (width == 64) { - // displays with width of 64 pixels are shifted by 32 - x0 += 32; - x1 += 32; - } - - uint16_t num_of_pages = height / 8; - set_col(x0, x1); - set_page(y0, y1); - - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - for (uint16_t i = 0; i < (width * num_of_pages); i++) { - raw_write(color); - } - - mp_hal_pin_high(mp_cs_pin); -} - -void driver_ssd1305_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len) { - set_col(line, line); - set_page(0, 63); - - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - for (uint8_t i = 0; i < len; i++) { - uint8_t byte = (uint8_t)((uint8_t *)p_bytes)[i]; - raw_write(byte); - } - - mp_hal_pin_high(mp_cs_pin); -} - -#endif diff --git a/nrf5/modules/display/oled_ssd1305_driver.h b/nrf5/modules/display/oled_ssd1305_driver.h deleted file mode 100644 index 5a030b7a8..000000000 --- a/nrf5/modules/display/oled_ssd1305_driver.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef OLED_SSD1305_DRIVER_H__ -#define OLED_SSD1305_DRIVER_H__ - -#include "py/mphal.h" - -#include "hal_spi.h" -#include "framebuffer.h" - -void driver_ssd1305_init(NRF_SPI_Type * p_instance, pin_obj_t * cs_pin, pin_obj_t * dc_pin, pin_obj_t * reset_pin); - -void driver_ssd1305_clear(uint16_t color); - -void driver_ssd1305_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len); - -#endif // OLED_SSD1305_DRIVER_H__ diff --git a/nrf5/modules/display/oled_ssd1305_obj.c b/nrf5/modules/display/oled_ssd1305_obj.c deleted file mode 100644 index 6b83a5355..000000000 --- a/nrf5/modules/display/oled_ssd1305_obj.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "genhdr/pins.h" - -#include "oled_ssd1305_driver.h" - -#if MICROPY_PY_DISPLAY_OLED_SSD1305 - -/// \moduleref display -/// \class SSD1305 - SSD1305 TFT LCD display driver. - -#include "moddisplay.h" -#include "framebuffer.h" -#include "pin.h" -#include "spi.h" - -typedef struct _oled_ssd1305_obj_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; - framebuffer_t * framebuffer; - machine_hard_spi_obj_t *spi; - pin_obj_t * pin_cs; - pin_obj_t * pin_dc; - pin_obj_t * pin_reset; -} oled_ssd1305_obj_t; - -#define OLED_SSD1305_COLOR_BLACK 0 -#define OLED_SSD1305_COLOR_WHITE 1 - -static void set_pixel(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color) { - oled_ssd1305_obj_t *self = (oled_ssd1305_obj_t *)p_display; - - if (color == OLED_SSD1305_COLOR_BLACK) { - framebuffer_pixel_clear(self->framebuffer, x, y); - } else { - framebuffer_pixel_set(self->framebuffer, x, y); - } -} - -/// \method __str__() -/// Return a string describing the SSD1305 object. -STATIC void oled_ssd1305_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - oled_ssd1305_obj_t *self = o; - - mp_printf(print, "SSD1305(SPI(mosi=(port=%u, pin=%u), miso=(port=%u, pin=%u), clk=(port=%u, pin=%u)),\n", - self->spi->pyb->spi->init.mosi_pin->port, - self->spi->pyb->spi->init.mosi_pin->pin, - self->spi->pyb->spi->init.miso_pin->port, - self->spi->pyb->spi->init.miso_pin->pin, - self->spi->pyb->spi->init.clk_pin->port, - self->spi->pyb->spi->init.clk_pin->pin); - - mp_printf(print, " cs=(port=%u, pin=%u), dc=(port=%u, pin=%u), reset=(port=%u, pin=%u),\n", - self->pin_cs->port, - self->pin_cs->pin, - self->pin_dc->port, - self->pin_dc->pin, - self->pin_reset->port, - self->pin_reset->pin); - - mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n", - self->framebuffer->screen_width, - self->framebuffer->screen_height, - self->framebuffer->line_orientation, - self->framebuffer->fb_stride, - self->framebuffer->fb_dirty_stride); -} - -// for make_new -enum { - ARG_NEW_WIDTH, - ARG_NEW_HEIGHT, - ARG_NEW_SPI, - ARG_NEW_CS, - ARG_NEW_DC, - ARG_NEW_RESET -}; - -/* - -Example for nrf51822 / pca10028: - -from machine import Pin, SPI -from display import SSD1305 -cs = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = SSD1305(128, 64, spi, cs, dc, reset) -draw.text(d, "Hello World!", 32, 32) -d.show() - -Example for nrf52832 / pca10040: - -from machine import Pin, SPI -from display import SSD1305 -import draw -cs = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("A11", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = SSD1305(128, 64, spi, cs, dc, reset) -draw.text(d, "Hello World!", 32, 32) -d.show() - -Example for nrf52840 / pca10056: - -from machine import Pin, SPI -from display import SSD1305 -import draw -cs = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("B2", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("B1", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = SSD1305(128, 64, spi, cs, dc, reset) -draw.text(d, "Hello World!", 32, 32) -d.show() - -*/ -STATIC mp_obj_t oled_ssd1305_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - static const mp_arg_t allowed_args[] = { - { ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_SPI, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_DC, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_RESET, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - oled_ssd1305_obj_t *s = m_new_obj_with_finaliser(oled_ssd1305_obj_t); - s->base.type = type; - s->draw_callbacks.pixel_set = set_pixel; - - mp_int_t width; - mp_int_t height; - - if (args[ARG_NEW_WIDTH].u_int > 0) { - width = args[ARG_NEW_WIDTH].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display width not set")); - } - - if (args[ARG_NEW_HEIGHT].u_int > 0) { - height = args[ARG_NEW_HEIGHT].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display height not set")); - } - - if (args[ARG_NEW_SPI].u_obj != MP_OBJ_NULL) { - s->spi = args[ARG_NEW_SPI].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display SPI not set")); - } - - if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) { - s->pin_cs = args[ARG_NEW_CS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display CS Pin not set")); - } - - if (args[ARG_NEW_DC].u_obj != MP_OBJ_NULL) { - s->pin_dc = args[ARG_NEW_DC].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display DC Pin not set")); - } - - if (args[ARG_NEW_RESET].u_obj != MP_OBJ_NULL) { - s->pin_reset = args[ARG_NEW_RESET].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Reset Pin not set")); - } - - framebuffer_init_t init_conf = { - .width = width, - .height = height, - .line_orientation = FRAMEBUFFER_LINE_DIR_VERTICAL, - .double_buffer = false - }; - - s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t)); - - framebuffer_init(s->framebuffer, &init_conf); - - driver_ssd1305_init(s->spi->pyb->spi->instance, s->pin_cs, s->pin_dc, s->pin_reset); - // Default to black background - driver_ssd1305_clear(0); - - framebuffer_clear(s->framebuffer); - - return MP_OBJ_FROM_PTR(s); -} - -// text - -/// \method fill(color) -/// Fill framebuffer with the color defined as argument. -STATIC mp_obj_t oled_ssd1305_fill(mp_obj_t self_in, mp_obj_t color) { - oled_ssd1305_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (color == MP_OBJ_NEW_SMALL_INT(OLED_SSD1305_COLOR_BLACK)) { - framebuffer_clear(self->framebuffer); - } else { - framebuffer_fill(self->framebuffer); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(oled_ssd1305_fill_obj, oled_ssd1305_fill); - -static void render(framebuffer_t * p_framebuffer) { - for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) { - if (p_framebuffer->fb_dirty[i].byte != 0) { - for (uint16_t b = 0; b < 8; b++) { - if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1)) { - uint16_t line_num = (i * 8) + b; - driver_ssd1305_update_line(line_num, - &p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride], - p_framebuffer->fb_stride); - } - } - - p_framebuffer->fb_dirty[i].byte = 0x00; - } - } -} - -/// \method show() -/// Display content in framebuffer. -STATIC mp_obj_t oled_ssd1305_show(size_t n_args, const mp_obj_t *args) { - oled_ssd1305_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - render(self->framebuffer); - framebuffer_flip(self->framebuffer); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1305_show_obj, 1, 2, oled_ssd1305_show); - -/// \method refresh([num_of_refresh]) -/// Refresh content in framebuffer. -/// -/// - With no argument, 1 refresh will be done. -/// - With `num_of_refresh` given, The whole framebuffer will be considered -/// dirty and will be refreshed the given number of times. -STATIC mp_obj_t oled_ssd1305_refresh(mp_obj_t self_in) { - oled_ssd1305_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(oled_ssd1305_refresh_obj, oled_ssd1305_refresh); - -/// \method pixel(x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color of the pixel in framebuffer will be returend. -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t oled_ssd1305_pixel(size_t n_args, const mp_obj_t *args) { - oled_ssd1305_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_int_t x = mp_obj_get_int(args[1]); - mp_int_t y = mp_obj_get_int(args[2]); - mp_int_t color = mp_obj_get_int(args[3]); - - set_pixel(self, x, y, color); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1305_pixel_obj, 4, 4, oled_ssd1305_pixel); - -/// \method pixel(text, x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color will be the opposite of background (fill color). -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t oled_ssd1305_text(size_t n_args, const mp_obj_t *args) { - oled_ssd1305_obj_t *self = MP_OBJ_TO_PTR(args[0]); - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color; - if (n_args >= 4) { - color = mp_obj_get_int(args[3]); - } - - //display_print_string(self->framebuffer, x, y, str); - - (void)x; - (void)y; - (void)self; - (void)str; - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1305_text_obj, 4, 5, oled_ssd1305_text); - -STATIC mp_obj_t oled_ssd1305_del(mp_obj_t self_in) { - oled_ssd1305_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(oled_ssd1305_del_obj, oled_ssd1305_del); - -STATIC const mp_map_elem_t oled_ssd1305_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)(&oled_ssd1305_del_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_fill), (mp_obj_t)(&oled_ssd1305_fill_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)(&oled_ssd1305_show_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)(&oled_ssd1305_text_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)(&oled_ssd1305_pixel_obj) }, -#if 0 - { MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&oled_ssd1305_bitmap_obj) }, -#endif - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(OLED_SSD1305_COLOR_BLACK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(OLED_SSD1305_COLOR_WHITE) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) }, -}; - -STATIC MP_DEFINE_CONST_DICT(oled_ssd1305_locals_dict, oled_ssd1305_locals_dict_table); - -const mp_obj_type_t oled_ssd1305_type = { - { &mp_type_type }, - .name = MP_QSTR_SSD1305, - .print = oled_ssd1305_print, - .make_new = oled_ssd1305_make_new, - .locals_dict = (mp_obj_t)&oled_ssd1305_locals_dict -}; - -#endif // MICROPY_PY_DISPLAY_OLED_SSD1305 diff --git a/nrf5/modules/display/oled_ssd1305_obj.h b/nrf5/modules/display/oled_ssd1305_obj.h deleted file mode 100644 index 23a9f935d..000000000 --- a/nrf5/modules/display/oled_ssd1305_obj.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef OLED_SSD1305_H__ -#define OLED_SSD1305_H__ - -#include <py/obj.h> - -extern const mp_obj_type_t oled_ssd1305_type; - -#endif // OLED_SSD1305_H__ - diff --git a/nrf5/modules/display/oled_ssd1306_driver.c b/nrf5/modules/display/oled_ssd1306_driver.c deleted file mode 100644 index 7083a6692..000000000 --- a/nrf5/modules/display/oled_ssd1306_driver.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <stdbool.h> - -#include "py/mphal.h" - -#include "oled_ssd1306_driver.h" -#include "hal_spi.h" -#include "hal_time.h" - -#include "framebuffer.h" - -#if MICROPY_PY_DISPLAY_OLED_SSD1306 - -static pin_obj_t * mp_cs_pin; -static pin_obj_t * mp_dc_pin; -static pin_obj_t * mp_reset_pin; -static NRF_SPI_Type * mp_instance; - - -static void raw_write(uint8_t value) -{ - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); - -} - -static void cmd_write(uint8_t value) -{ - mp_hal_pin_low(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - hal_spi_master_tx_rx(mp_instance, 1, &value, NULL); - - mp_hal_pin_high(mp_cs_pin); -} - -#define SET_CONTRAST (0x81) -#define SET_ENTIRE_ON (0xa4) -#define SET_NORM_INV (0xa6) -#define SET_DISP (0xae) -#define SET_MEM_ADDR (0x20) -#define SET_COL_ADDR (0x21) -#define SET_PAGE_ADDR (0x22) -#define SET_DISP_START_LINE (0x40) -#define SET_SEG_REMAP (0xa0) -#define SET_MUX_RATIO (0xa8) -#define SET_COM_OUT_DIR (0xc0) -#define SET_DISP_OFFSET (0xd3) -#define SET_COM_PIN_CFG (0xda) -#define SET_DISP_CLK_DIV (0xd5) -#define SET_PRECHARGE (0xd9) -#define SET_VCOM_DESEL (0xdb) -#define SET_CHARGE_PUMP (0x8d) - -void driver_ssd1306_init(NRF_SPI_Type * p_instance, pin_obj_t * p_cs_pin, pin_obj_t * p_dc_pin, pin_obj_t * p_reset_pin) -{ - mp_instance = p_instance; - mp_cs_pin = p_cs_pin; - mp_dc_pin = p_dc_pin; - mp_reset_pin = p_reset_pin; - - mp_hal_pin_high(mp_cs_pin); - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_high(mp_reset_pin); - - // power on display - mp_hal_pin_high(mp_reset_pin); - mp_hal_delay_ms(1); - mp_hal_pin_low(mp_reset_pin); - mp_hal_delay_ms(10); - mp_hal_pin_high(mp_reset_pin); - - // Turn off - cmd_write(SET_DISP | 0x00); // off - - // address setting - cmd_write(SET_MEM_ADDR); - cmd_write(0x00); // horizontal - - // resolution and layout - cmd_write(SET_DISP_START_LINE | 0x00); - cmd_write(SET_SEG_REMAP | 0x01); // column addr 127 mapped to SEG0 - cmd_write(SET_MUX_RATIO); - - uint16_t height = 64; // TODO: configurable - cmd_write(height - 1); // height - 1 - cmd_write(SET_COM_OUT_DIR | 0x08); // scan from COM[N] to COM0 - cmd_write(SET_DISP_OFFSET); - cmd_write(0x00); - cmd_write(SET_COM_PIN_CFG); - if (height == 32) { - cmd_write(0x02); - } else { - cmd_write(0x12); - } - // timing and driving scheme - cmd_write(SET_DISP_CLK_DIV); - cmd_write(0x80); - cmd_write(SET_PRECHARGE); - bool external_vcc = false; - if (external_vcc == true) { - cmd_write(0x22); - } else { - cmd_write(0xf1); - } - cmd_write(SET_VCOM_DESEL); - cmd_write(0x30); // 0.83*Vcc - // display - cmd_write(SET_CONTRAST); - cmd_write(0xff); // maximum - cmd_write(SET_ENTIRE_ON); // output follows RAM contents - cmd_write(SET_NORM_INV); // not inverted - // charge pump - cmd_write(SET_CHARGE_PUMP); - if (external_vcc == true) { - cmd_write(0x10); - } else { - cmd_write(0x14); - } - // on - cmd_write(SET_DISP | 0x01); - -} - -static void set_col(uint16_t start_col, uint16_t end_col) -{ - cmd_write(SET_COL_ADDR); // column command address - cmd_write(start_col & 0xFF ); - cmd_write(end_col & 0xFF); -} - -static void set_page(uint16_t start_page, uint16_t end_page) -{ - cmd_write(SET_PAGE_ADDR); // page command address - cmd_write(start_page & 0xFF); - cmd_write(end_page & 0xFF); -} - -void driver_ssd1306_clear(uint16_t color) -{ - uint16_t width = 128; - uint16_t height = 64; - - uint16_t x0 = 0; - uint16_t x1 = width - 1; - uint16_t y0 = 0; - uint16_t y1 = height -1; - - if (width == 64) { - // displays with width of 64 pixels are shifted by 32 - x0 += 32; - x1 += 32; - } - - uint16_t num_of_pages = height / 8; - set_col(x0, x1); - set_page(y0, y1); - - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - for (uint16_t i = 0; i < (width * num_of_pages); i++) { - raw_write(color); - } - - mp_hal_pin_high(mp_cs_pin); -} - -void driver_ssd1306_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len) { - set_col(line, line); - set_page(0, 63); - - mp_hal_pin_high(mp_dc_pin); - mp_hal_pin_low(mp_cs_pin); - - for (uint8_t i = 0; i < len; i++) { - uint8_t byte = (uint8_t)((uint8_t *)p_bytes)[i]; - raw_write(byte); - } - - mp_hal_pin_high(mp_cs_pin); -} - -#endif diff --git a/nrf5/modules/display/oled_ssd1306_driver.h b/nrf5/modules/display/oled_ssd1306_driver.h deleted file mode 100644 index c9b33ab02..000000000 --- a/nrf5/modules/display/oled_ssd1306_driver.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef OLED_SSD1306_DRIVER_H__ -#define OLED_SSD1306_DRIVER_H__ - -#include "py/mphal.h" - -#include "hal_spi.h" -#include "framebuffer.h" - -void driver_ssd1306_init(NRF_SPI_Type * p_instance, pin_obj_t * cs_pin, pin_obj_t * dc_pin, pin_obj_t * reset_pin); - -void driver_ssd1306_clear(uint16_t color); - -void driver_ssd1306_update_line(uint16_t line, framebuffer_byte_t * p_bytes, uint16_t len); - -#endif // OLED_SSD1306_DRIVER_H__ diff --git a/nrf5/modules/display/oled_ssd1306_obj.c b/nrf5/modules/display/oled_ssd1306_obj.c deleted file mode 100644 index 55e509499..000000000 --- a/nrf5/modules/display/oled_ssd1306_obj.c +++ /dev/null @@ -1,370 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "py/obj.h" -#include "py/runtime.h" -#include "py/mphal.h" -#include "genhdr/pins.h" - -#include "oled_ssd1306_driver.h" - -#if MICROPY_PY_DISPLAY_OLED_SSD1306 - -/// \moduleref display -/// \class SSD1306 - SSD1306 TFT LCD display driver. - -#include "moddisplay.h" -#include "framebuffer.h" -#include "pin.h" -#include "spi.h" - -typedef struct _oled_ssd1306_obj_t { - mp_obj_base_t base; - display_draw_callbacks_t draw_callbacks; - framebuffer_t * framebuffer; - machine_hard_spi_obj_t *spi; - pin_obj_t * pin_cs; - pin_obj_t * pin_dc; - pin_obj_t * pin_reset; -} oled_ssd1306_obj_t; - -#define OLED_SSD1306_COLOR_BLACK 0 -#define OLED_SSD1306_COLOR_WHITE 1 - -static void set_pixel(void * p_display, - uint16_t x, - uint16_t y, - uint16_t color) { - oled_ssd1306_obj_t *self = (oled_ssd1306_obj_t *)p_display; - - if (color == OLED_SSD1306_COLOR_BLACK) { - framebuffer_pixel_clear(self->framebuffer, x, y); - } else { - framebuffer_pixel_set(self->framebuffer, x, y); - } -} - -/// \method __str__() -/// Return a string describing the SSD1306 object. -STATIC void oled_ssd1306_print(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind) { - oled_ssd1306_obj_t *self = o; - - mp_printf(print, "SSD1306(SPI(mosi=(port=%u, pin=%u), miso=(port=%u, pin=%u), clk=(port=%u, pin=%u)),\n", - self->spi->pyb->spi->init.mosi_pin->port, - self->spi->pyb->spi->init.mosi_pin->pin, - self->spi->pyb->spi->init.miso_pin->port, - self->spi->pyb->spi->init.miso_pin->pin, - self->spi->pyb->spi->init.clk_pin->port, - self->spi->pyb->spi->init.clk_pin->pin); - - mp_printf(print, " cs=(port=%u, pin=%u), dc=(port=%u, pin=%u), reset=(port=%u, pin=%u),\n", - self->pin_cs->port, - self->pin_cs->pin, - self->pin_dc->port, - self->pin_dc->pin, - self->pin_reset->port, - self->pin_reset->pin); - - mp_printf(print, " FB(width=%u, height=%u, dir=%u, fb_stride=%u, fb_dirty_stride=%u))\n", - self->framebuffer->screen_width, - self->framebuffer->screen_height, - self->framebuffer->line_orientation, - self->framebuffer->fb_stride, - self->framebuffer->fb_dirty_stride); -} - -// for make_new -enum { - ARG_NEW_WIDTH, - ARG_NEW_HEIGHT, - ARG_NEW_SPI, - ARG_NEW_CS, - ARG_NEW_DC, - ARG_NEW_RESET -}; - -/* - -Example for nrf51822 / pca10028: - -from machine import Pin, SPI -from display import SSD1306 -cs = Pin("A14", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = SSD1306(128, 64, spi, cs, dc, reset) -d.text("Hello World!", 32, 32) -d.show() - -Example for nrf52832 / pca10040: - -from machine import Pin, SPI -from display import SSD1306 -cs = Pin("A13", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("A12", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("A11", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = SSD1306(128, 64, spi, cs, dc, reset) -d.text("Hello World!", 32, 32) -d.show() - -Example for nrf52840 / pca10056: - -from machine import Pin, SPI -from display import SSD1306 -cs = Pin("B3", mode=Pin.OUT, pull=Pin.PULL_UP) -reset = Pin("B2", mode=Pin.OUT, pull=Pin.PULL_UP) -dc = Pin("B1", mode=Pin.OUT, pull=Pin.PULL_UP) -spi = SPI(0, baudrate=8000000) -d = SSD1306(128, 64, spi, cs, dc, reset) -d.text("Hello World!", 32, 32) -d.show() - -*/ -STATIC mp_obj_t oled_ssd1306_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { - static const mp_arg_t allowed_args[] = { - { ARG_NEW_WIDTH, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_HEIGHT, MP_ARG_REQUIRED | MP_ARG_INT }, - { ARG_NEW_SPI, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_CS, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_DC, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - { ARG_NEW_RESET, MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, - }; - - // parse args - mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); - - oled_ssd1306_obj_t *s = m_new_obj_with_finaliser(oled_ssd1306_obj_t); - s->base.type = type; - s->draw_callbacks.pixel_set = set_pixel; - - mp_int_t width; - mp_int_t height; - - if (args[ARG_NEW_WIDTH].u_int > 0) { - width = args[ARG_NEW_WIDTH].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display width not set")); - } - - if (args[ARG_NEW_HEIGHT].u_int > 0) { - height = args[ARG_NEW_HEIGHT].u_int; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display height not set")); - } - - if (args[ARG_NEW_SPI].u_obj != MP_OBJ_NULL) { - s->spi = args[ARG_NEW_SPI].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display SPI not set")); - } - - if (args[ARG_NEW_CS].u_obj != MP_OBJ_NULL) { - s->pin_cs = args[ARG_NEW_CS].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display CS Pin not set")); - } - - if (args[ARG_NEW_DC].u_obj != MP_OBJ_NULL) { - s->pin_dc = args[ARG_NEW_DC].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display DC Pin not set")); - } - - if (args[ARG_NEW_RESET].u_obj != MP_OBJ_NULL) { - s->pin_reset = args[ARG_NEW_RESET].u_obj; - } else { - nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, - "Display Reset Pin not set")); - } - - framebuffer_init_t init_conf = { - .width = width, - .height = height, - .line_orientation = FRAMEBUFFER_LINE_DIR_VERTICAL, - .double_buffer = false - }; - - s->framebuffer = m_new(framebuffer_t, sizeof(framebuffer_t)); - - framebuffer_init(s->framebuffer, &init_conf); - - driver_ssd1306_init(s->spi->pyb->spi->instance, s->pin_cs, s->pin_dc, s->pin_reset); - // Default to black background - driver_ssd1306_clear(0); - - framebuffer_clear(s->framebuffer); - - return MP_OBJ_FROM_PTR(s); -} - -// text - -/// \method fill(color) -/// Fill framebuffer with the color defined as argument. -STATIC mp_obj_t oled_ssd1306_fill(mp_obj_t self_in, mp_obj_t color) { - oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(self_in); - - if (color == MP_OBJ_NEW_SMALL_INT(OLED_SSD1306_COLOR_BLACK)) { - framebuffer_clear(self->framebuffer); - } else { - framebuffer_fill(self->framebuffer); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_2(oled_ssd1306_fill_obj, oled_ssd1306_fill); - -static void render(framebuffer_t * p_framebuffer) { - for (uint16_t i = 0; i < p_framebuffer->fb_dirty_stride; i++) { - if (p_framebuffer->fb_dirty[i].byte != 0) { - for (uint16_t b = 0; b < 8; b++) { - if ((((p_framebuffer->fb_dirty[i].byte >> b) & 0x01) == 1)) { - uint16_t line_num = (i * 8) + b; - driver_ssd1306_update_line(line_num, - &p_framebuffer->fb_new[line_num * p_framebuffer->fb_stride], - p_framebuffer->fb_stride); - } - } - - p_framebuffer->fb_dirty[i].byte = 0x00; - } - } -} - -/// \method show() -/// Display content in framebuffer. -STATIC mp_obj_t oled_ssd1306_show(size_t n_args, const mp_obj_t *args) { - oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(args[0]); - - render(self->framebuffer); - framebuffer_flip(self->framebuffer); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1306_show_obj, 1, 2, oled_ssd1306_show); - -/// \method refresh([num_of_refresh]) -/// Refresh content in framebuffer. -/// -/// - With no argument, 1 refresh will be done. -/// - With `num_of_refresh` given, The whole framebuffer will be considered -/// dirty and will be refreshed the given number of times. -STATIC mp_obj_t oled_ssd1306_refresh(mp_obj_t self_in) { - oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(oled_ssd1306_refresh_obj, oled_ssd1306_refresh); - -/// \method pixel(x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color of the pixel in framebuffer will be returend. -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t oled_ssd1306_pixel(size_t n_args, const mp_obj_t *args) { - oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(args[0]); - mp_int_t x = mp_obj_get_int(args[1]); - mp_int_t y = mp_obj_get_int(args[2]); - mp_int_t color = mp_obj_get_int(args[3]); - - set_pixel(self, x, y, color); - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1306_pixel_obj, 4, 4, oled_ssd1306_pixel); - -/// \method pixel(text, x, y, [color]) -/// Write one pixel in framebuffer. -/// -/// - With no argument, the color will be the opposite of background (fill color). -/// - With `color` given, sets the pixel to the color given. -STATIC mp_obj_t oled_ssd1306_text(size_t n_args, const mp_obj_t *args) { - oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(args[0]); - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color; - if (n_args >= 4) { - color = mp_obj_get_int(args[3]); - } - - //display_print_string(self->framebuffer, x, y, str); - - (void)x; - (void)y; - (void)self; - (void)str; - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(oled_ssd1306_text_obj, 4, 5, oled_ssd1306_text); - -STATIC mp_obj_t oled_ssd1306_del(mp_obj_t self_in) { - oled_ssd1306_obj_t *self = MP_OBJ_TO_PTR(self_in); - - (void)self; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(oled_ssd1306_del_obj, oled_ssd1306_del); - -STATIC const mp_map_elem_t oled_ssd1306_locals_dict_table[] = { - { MP_OBJ_NEW_QSTR(MP_QSTR___del__), (mp_obj_t)(&oled_ssd1306_del_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_fill), (mp_obj_t)(&oled_ssd1306_fill_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_show), (mp_obj_t)(&oled_ssd1306_show_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)(&oled_ssd1306_text_obj) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_pixel), (mp_obj_t)(&oled_ssd1306_pixel_obj) }, -#if 0 - { MP_OBJ_NEW_QSTR(MP_QSTR_bitmap), (mp_obj_t)(&oled_ssd1306_bitmap_obj) }, -#endif - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_BLACK), MP_OBJ_NEW_SMALL_INT(OLED_SSD1306_COLOR_BLACK) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_COLOR_WHITE), MP_OBJ_NEW_SMALL_INT(OLED_SSD1306_COLOR_WHITE) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_VERTICAL), MP_OBJ_NEW_SMALL_INT(0) }, - { MP_OBJ_NEW_QSTR(MP_QSTR_HORIZONTAL), MP_OBJ_NEW_SMALL_INT(1) }, -}; - -STATIC MP_DEFINE_CONST_DICT(oled_ssd1306_locals_dict, oled_ssd1306_locals_dict_table); - -const mp_obj_type_t oled_ssd1306_type = { - { &mp_type_type }, - .name = MP_QSTR_SSD1306, - .print = oled_ssd1306_print, - .make_new = oled_ssd1306_make_new, - .locals_dict = (mp_obj_t)&oled_ssd1306_locals_dict -}; - -#endif // MICROPY_PY_DISPLAY_OLED_SSD1306 diff --git a/nrf5/modules/display/oled_ssd1306_obj.h b/nrf5/modules/display/oled_ssd1306_obj.h deleted file mode 100644 index 37a00b1a8..000000000 --- a/nrf5/modules/display/oled_ssd1306_obj.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef OLED_SSD1306_H__ -#define OLED_SSD1306_H__ - -#include <py/obj.h> - -extern const mp_obj_type_t oled_ssd1306_type; - -#endif // OLED_SSD1306_H__ - diff --git a/nrf5/modules/display/rgb16.h b/nrf5/modules/display/rgb16.h deleted file mode 100644 index 96977d412..000000000 --- a/nrf5/modules/display/rgb16.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#ifndef RGB16_H__ -#define RGB16_H__ - -#define RGB16(rrrrr32, gggggg64, bbbbb32) \ -(((rrrrr32 & 248) | gggggg64 >> 5) << 8) + ((gggggg64 & 28) << 3 | bbbbb32 >> 3) - -#endif // RGB16_H__ diff --git a/nrf5/modules/graphic/draw.c b/nrf5/modules/graphic/draw.c deleted file mode 100644 index 3dfb60a5b..000000000 --- a/nrf5/modules/graphic/draw.c +++ /dev/null @@ -1,189 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include <string.h> - -#include "py/nlr.h" -#include "py/runtime.h" -#include "py/mphal.h" - -#include "moddisplay.h" -#include "font_petme128_8x8.h" - -#if MICROPY_PY_DISPLAY_GRAPHICS - -/// \method circle(display, radius, x, y, color, [fill]) -/// Draw a circle in the display framebuffer. -STATIC mp_obj_t draw_circle(mp_uint_t n_args, const mp_obj_t *args) { - display_t * screen = MP_OBJ_TO_PTR(args[0]); - - mp_uint_t radius = mp_obj_get_int(args[1]); - mp_uint_t xc = mp_obj_get_int(args[2]); - mp_uint_t yc = mp_obj_get_int(args[3]); - mp_uint_t color = mp_obj_get_int(args[4]); - - pixel_set_callback_t pixel_set_cb = screen->draw_callbacks.pixel_set; - - // algorithm borrowed from: - // http://stackoverflow.com/a/35541416 - - uint16_t y = radius; - uint16_t x = 0; - int d = 3 - 2 * radius; - - while (x <= y) { - for (uint16_t hor = 0; hor < x + 1; hor++) { - pixel_set_cb(screen, xc+hor, yc+y, color); - pixel_set_cb(screen, xc-hor, yc+y, color); - pixel_set_cb(screen, xc+hor, yc-y, color); - pixel_set_cb(screen, xc-hor, yc-y, color); - pixel_set_cb(screen, xc+x, yc+hor, color); - pixel_set_cb(screen, xc-x, yc+hor, color); - pixel_set_cb(screen, xc+x, yc-hor, color); - pixel_set_cb(screen, xc-x, yc-hor, color); - pixel_set_cb(screen, xc+hor, yc+x, color); - pixel_set_cb(screen, xc-hor, yc+x, color); - pixel_set_cb(screen, xc+hor, yc-x, color); - pixel_set_cb(screen, xc-hor, yc-x, color); - pixel_set_cb(screen, xc+y, yc+hor, color); - pixel_set_cb(screen, xc-y, yc+hor, color); - pixel_set_cb(screen, xc+y, yc-hor, color); - pixel_set_cb(screen, xc-y, yc-hor, color); - } - - if (d < 0) { - d = d + 4 * x + 6; - } else { - d = d + 4 * (x-y) + 10; - y = y - 1; - } - - x = x + 1; - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(graphics_draw_circle_obj, 5, 6, draw_circle); - -STATIC void graphics_draw_char(display_t * screen, uint16_t x, uint16_t y, char ch, uint16_t color, uint8_t font_size) { - - pixel_set_callback_t pixel_set_cb = screen->draw_callbacks.pixel_set; - - uint16_t col = x; - for (uint8_t i = 0; i < 8; i++) { - uint16_t current_col = col + (i * font_size); - - for (uint8_t y_pos = 0; y_pos < 8; y_pos++) { - if ((((uint8_t)font_petme128_8x8[((ch - 32) * 8) + i]) >> y_pos) & 0x01) { - for (uint8_t s_w = 0; s_w < font_size; s_w++) { - for (uint8_t s_h = 0; s_h < font_size; s_h++) { - - uint16_t pix_x = current_col + s_w; - uint16_t pix_y = y + (y_pos * font_size) + s_h; - - pixel_set_cb(screen, pix_x, pix_y, color); - } - } - } else { - for (uint8_t s_w = 0; s_w < font_size; s_w++) { - for (uint8_t s_h = 0; s_h < font_size; s_h++) { - uint16_t pix_x = current_col + s_w; - uint16_t pix_y = y + (y_pos * font_size) + s_h; - - pixel_set_cb(screen, pix_x, pix_y, !color); - } - } - } - } - } -} - -STATIC mp_obj_t graphics_draw_text(size_t n_args, const mp_obj_t *args) { - display_t * screen = MP_OBJ_TO_PTR(args[0]); - - const char *str = mp_obj_str_get_str(args[1]); - mp_int_t x = mp_obj_get_int(args[2]); - mp_int_t y = mp_obj_get_int(args[3]); - mp_int_t color = 0; - if (n_args >= 4) { - color = mp_obj_get_int(args[4]); - } - - uint8_t font_size = 1; - - uint16_t str_len = strlen(str); - for (uint16_t i = 0; i < str_len; i++) { - graphics_draw_char(screen, x + (i * 8 * font_size), y, str[i], color, font_size); - } - - (void)color; - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(graphics_draw_text_obj, 4, 5, graphics_draw_text); - -/// \method rectangle(display, x0, y0, x1, y1, color, [fill]) -STATIC mp_obj_t draw_rectangle(mp_uint_t n_args, const mp_obj_t *args) { - display_t * screen = MP_OBJ_TO_PTR(args[0]); - mp_uint_t x0 = mp_obj_get_int(args[1]); - mp_uint_t y0 = mp_obj_get_int(args[2]); - mp_uint_t x1 = mp_obj_get_int(args[3]); - mp_uint_t y1 = mp_obj_get_int(args[4]); - mp_uint_t color = mp_obj_get_int(args[5]); - - pixel_set_callback_t pixel_set_cb = screen->draw_callbacks.pixel_set; - - // horizontals - for (mp_uint_t hpos = x0; hpos <= x1; hpos++) { - pixel_set_cb(screen, hpos, y0, color); - pixel_set_cb(screen, hpos, y1, color); - } - // verticals - for (mp_uint_t vpos = y0; vpos <= y1; vpos++) { - pixel_set_cb(screen, x0, vpos, color); - pixel_set_cb(screen, x1, vpos, color); - } - - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(graphics_draw_rectangle_obj, 6, 7, draw_rectangle); - - -STATIC const mp_map_elem_t graphics_globals_dict_table[] = { - // class methods - { MP_OBJ_NEW_QSTR(MP_QSTR_circle), (mp_obj_t)&graphics_draw_circle_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_text), (mp_obj_t)&graphics_draw_text_obj }, - { MP_OBJ_NEW_QSTR(MP_QSTR_rectangle), (mp_obj_t)&graphics_draw_rectangle_obj }, -}; - -STATIC MP_DEFINE_CONST_DICT(graphics_globals_dict, graphics_globals_dict_table); - -const mp_obj_module_t graphics_module = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t*)&graphics_globals_dict, -}; - -#endif // MICROPY_PY_DISPLAY_GRAPHICS diff --git a/nrf5/modules/graphic/draw.h b/nrf5/modules/graphic/draw.h deleted file mode 100644 index 79419c686..000000000 --- a/nrf5/modules/graphic/draw.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2017 Glenn Ruben Bakke - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - diff --git a/nrf5/mpconfigport.h b/nrf5/mpconfigport.h index de50aa57e..05b3f583c 100644 --- a/nrf5/mpconfigport.h +++ b/nrf5/mpconfigport.h @@ -147,60 +147,6 @@ #define MICROPY_PY_NETWORK (1) #endif - - -#ifndef MICROPY_PY_DISPLAY - -#define MICROPY_PY_DISPLAY (0) -#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (0) -#define MICROPY_PY_DISPLAY_LCD_ILI9341 (0) -#define MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX (0) -#define MICROPY_PY_DISPLAY_LCD_SSD1289 (0) -#define MICROPY_PY_DISPLAY_OLED_SSD1306 (0) -#define MICROPY_PY_DISPLAY_OLED_SSD1305 (0) -#define MICROPY_PY_DISPLAY_FRAMEBUFFER (0) -#define MICROPY_PY_DISPLAY_GRAPHICS (0) - -#elif MICROPY_PY_DISPLAY - -// Default to include Monochrome Framebuffer -// if display module is selected. -#ifndef MICROPY_PY_DISPLAY_FRAMEBUFFER -#define MICROPY_PY_DISPLAY_FRAMEBUFFER (1) -#endif - -// Default to include graphics library if -// display modue is selected. -#ifndef MICROPY_PY_DISPLAY_GRAPHICS -#define MICROPY_PY_DISPLAY_GRAPHICS (1) -#endif - -#ifndef MICROPY_PY_DISPLAY_EPAPER_SLD00200P -#define MICROPY_PY_DISPLAY_EPAPER_SLD00200P (0) -#endif - -#ifndef MICROPY_PY_DISPLAY_LCD_ILI9341 -#define MICROPY_PY_DISPLAY_LCD_ILI9341 (0) -#endif - -#ifndef MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX -#define MICROPY_PY_DISPLAY_LCD_LS0XXB7DXXX (0) -#endif - -#ifndef MICROPY_PY_DISPLAY_LCD_SSD1289 -#define MICROPY_PY_DISPLAY_LCD_SSD1289 (0) -#endif - -#ifndef MICROPY_PY_DISPLAY_OLED_SSD1305 -#define MICROPY_PY_DISPLAY_OLED_SSD1305 (0) -#endif - -#ifndef MICROPY_PY_DISPLAY_OLED_SSD1306 -#define MICROPY_PY_DISPLAY_OLED_SSD1306 (0) -#endif - -#endif // MICROPY_PY_DISPLAY - #define MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF (1) #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (0) @@ -240,9 +186,6 @@ extern const struct _mp_obj_module_t mp_module_utime; extern const struct _mp_obj_module_t mp_module_uos; extern const struct _mp_obj_module_t mp_module_usocket; extern const struct _mp_obj_module_t mp_module_network; -extern const struct _mp_obj_module_t mp_module_lcd_mono_fb; -extern const struct _mp_obj_module_t mp_module_display; -extern const struct _mp_obj_module_t graphics_module; extern const struct _mp_obj_module_t mp_module_ubluepy; #if MICROPY_PY_USOCKET @@ -259,24 +202,6 @@ extern const struct _mp_obj_module_t mp_module_ubluepy; #define NETWORK_BUILTIN_MODULE #endif -#if MICROPY_PY_LCD_MONO_FB -#define LCD_MONO_FB_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_lcd_mono_fb), (mp_obj_t)&mp_module_lcd_mono_fb }, -#else -#define LCD_MONO_FB_MODULE -#endif - -#if MICROPY_PY_DISPLAY -#define DISPLAY_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_display), (mp_obj_t)&mp_module_display }, -#else -#define DISPLAY_MODULE -#endif - -#if MICROPY_PY_DISPLAY_GRAPHICS -#define GRAPHICS_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_draw), (mp_obj_t)&graphics_module }, -#else -#define GRAPHICS_MODULE -#endif - #if MICROPY_PY_UBLUEPY #define UBLUEPY_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_ubluepy), (mp_obj_t)&mp_module_ubluepy }, #else @@ -295,9 +220,6 @@ extern const struct _mp_obj_module_t ble_module; { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \ SOCKET_BUILTIN_MODULE \ NETWORK_BUILTIN_MODULE \ - LCD_MONO_FB_MODULE \ - DISPLAY_MODULE \ - GRAPHICS_MODULE \ UBLUEPY_MODULE \ @@ -308,9 +230,6 @@ extern const struct _mp_obj_module_t ble_module; { MP_OBJ_NEW_QSTR(MP_QSTR_machine), (mp_obj_t)&machine_module }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \ { MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \ - LCD_MONO_FB_MODULE \ - DISPLAY_MODULE \ - GRAPHICS_MODULE \ #endif // BLUETOOTH_SD |
