summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorLimor "Ladyada" Fried <limor@ladyada.net>2020-11-14 11:47:45 -0500
committerGitHub <noreply@github.com>2020-11-14 11:47:45 -0500
commitf2e911ad91db7c04673e76c884abbc19494a4e7f (patch)
tree47f6a854677781382d715791e7d7534d71887f7a /ports
parent9169878ebbeab3fc62785b9bf753499ad9033321 (diff)
parentbda3267432aee57e704a20308b724369cceeb6ca (diff)
Merge pull request #3680 from tannewt/magtag_builtin_display
Add board.DISPLAY to MagTag. Fix luma computation
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h4
-rw-r--r--ports/atmel-samd/common-hal/audiobusio/PDMIn.c2
-rw-r--r--ports/atmel-samd/common-hal/displayio/ParallelBus.c3
-rw-r--r--ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/board.c122
-rw-r--r--ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c4
-rw-r--r--ports/esp32s2/common-hal/displayio/ParallelBus.c3
-rw-r--r--ports/mimxrt10xx/common-hal/displayio/ParallelBus.c3
-rw-r--r--ports/nrf/common-hal/displayio/ParallelBus.c3
-rw-r--r--ports/stm/common-hal/displayio/ParallelBus.c3
9 files changed, 141 insertions, 6 deletions
diff --git a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h
index 04565feb4..d48c596ac 100644
--- a/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h
+++ b/ports/atmel-samd/boards/metro_m0_express/mpconfigboard.h
@@ -33,6 +33,10 @@
#define DEFAULT_UART_BUS_RX (&pin_PA11)
#define DEFAULT_UART_BUS_TX (&pin_PA10)
+// These pins are connected to the external crystal.
+#define IGNORE_PIN_PA00 1
+#define IGNORE_PIN_PA01 1
+
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
index 21474ab3b..3c9ec05c2 100644
--- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
+++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c
@@ -326,7 +326,7 @@ static void setup_dma(audiobusio_pdmin_obj_t* self, uint32_t length,
// higher sample rate than specified. Then after the audio is
// recorded, a more expensive filter non-real-time filter could be
// used to down-sample and low-pass.
-uint16_t sinc_filter [OVERSAMPLING] = {
+const uint16_t sinc_filter [OVERSAMPLING] = {
0, 2, 9, 21, 39, 63, 94, 132,
179, 236, 302, 379, 467, 565, 674, 792,
920, 1055, 1196, 1341, 1487, 1633, 1776, 1913,
diff --git a/ports/atmel-samd/common-hal/displayio/ParallelBus.c b/ports/atmel-samd/common-hal/displayio/ParallelBus.c
index 405c08c64..f10dd2993 100644
--- a/ports/atmel-samd/common-hal/displayio/ParallelBus.c
+++ b/ports/atmel-samd/common-hal/displayio/ParallelBus.c
@@ -129,7 +129,8 @@ bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
return true;
}
-void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->command, byte_type == DISPLAY_DATA);
uint32_t* clear_write = (uint32_t*) &self->write_group->OUTCLR.reg;
diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/board.c b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/board.c
index 9f708874b..ecd44e423 100644
--- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/board.c
+++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/board.c
@@ -26,7 +26,83 @@
#include "boards/board.h"
#include "mpconfigboard.h"
+#include "shared-bindings/busio/SPI.h"
+#include "shared-bindings/displayio/FourWire.h"
#include "shared-bindings/microcontroller/Pin.h"
+#include "shared-module/displayio/__init__.h"
+#include "supervisor/shared/board.h"
+
+#define DELAY 0x80
+
+// This is an ILO373 control chip. The display is a 2.9" grayscale EInk.
+
+const uint8_t display_start_sequence[] = {
+ 0x01, 5, 0x03, 0x00, 0x2b, 0x2b, 0x13, // power setting
+ 0x06, 3, 0x17, 0x17, 0x17, // booster soft start
+ 0x04, DELAY, 200, // power on and wait 200 ms
+ 0x00, 1, 0x7f, // panel setting
+ 0x50, 1, 0x97, // CDI setting
+ 0x30, 1, 0x3c, // PLL set to 50 Hx (M = 7, N = 4)
+ 0x61, 3, 0x80, 0x01, 0x28, // Resolution
+ 0x82, DELAY | 1, 0x12, 50, // VCM DC and delay 50ms
+
+ // Look up tables for voltage sequence for pixel transition
+ // Common voltage
+ 0x20, 0x2a,
+ 0x00, 0x0a, 0x00, 0x00, 0x00, 0x01,
+ 0x60, 0x14, 0x14, 0x00, 0x00, 0x01,
+ 0x00, 0x14, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x13, 0x0a, 0x01, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ // White to white
+ 0x21, 0x2a,
+ 0x40, 0x0a, 0x00, 0x00, 0x00, 0x01,
+ 0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
+ 0x10, 0x14, 0x0a, 0x00, 0x00, 0x01,
+ 0xa0, 0x13, 0x01, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ // Black to white
+ 0x22, 0x2a,
+ 0x40, 0x0a, 0x00, 0x00, 0x00, 0x01,
+ 0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
+ 0x00, 0x14, 0x0a, 0x00, 0x00, 0x01,
+ 0x99, 0x0c, 0x01, 0x03, 0x04, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ // White to black
+ 0x23, 0x2a,
+ 0x40, 0x0a, 0x00, 0x00, 0x00, 0x01,
+ 0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
+ 0x00, 0x14, 0x0a, 0x00, 0x00, 0x01,
+ 0x99, 0x0b, 0x04, 0x04, 0x01, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+
+ // Black to black
+ 0x24, 0x2a,
+ 0x80, 0x0a, 0x00, 0x00, 0x00, 0x01,
+ 0x90, 0x14, 0x14, 0x00, 0x00, 0x01,
+ 0x20, 0x14, 0x0a, 0x00, 0x00, 0x01,
+ 0x50, 0x13, 0x01, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+};
+
+const uint8_t display_stop_sequence[] = {
+ 0x50, 0x01, 0x17, // CDI Setting
+ 0x82, 0x01, 0x00, // VCM DC to -0.1V
+ 0x02, 0x00 // Power off
+};
void board_init(void) {
// USB
@@ -36,6 +112,52 @@ void board_init(void) {
// Debug UART
common_hal_never_reset_pin(&pin_GPIO43);
common_hal_never_reset_pin(&pin_GPIO44);
+
+ busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
+ common_hal_busio_spi_construct(spi, &pin_GPIO36, &pin_GPIO35, NULL);
+ common_hal_busio_spi_never_reset(spi);
+
+ displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
+ bus->base.type = &displayio_fourwire_type;
+ common_hal_displayio_fourwire_construct(bus,
+ spi,
+ &pin_GPIO7, // EPD_DC Command or data
+ &pin_GPIO8, // EPD_CS Chip select
+ &pin_GPIO6, // EPD_RST Reset
+ 4000000, // Baudrate
+ 0, // Polarity
+ 0); // Phase
+
+ displayio_epaperdisplay_obj_t* display = &displays[0].epaper_display;
+ display->base.type = &displayio_epaperdisplay_type;
+ common_hal_displayio_epaperdisplay_construct(
+ display,
+ bus,
+ display_start_sequence, sizeof(display_start_sequence),
+ display_stop_sequence, sizeof(display_stop_sequence),
+ 296, // width
+ 128, // height
+ 160, // ram_width
+ 296, // ram_height
+ 0, // colstart
+ 0, // rowstart
+ 270, // rotation
+ NO_COMMAND, // set_column_window_command
+ NO_COMMAND, // set_row_window_command
+ NO_COMMAND, // set_current_column_command
+ NO_COMMAND, // set_current_row_command
+ 0x10, // write_black_ram_command
+ false, // black_bits_inverted
+ 0x13, // write_color_ram_command
+ false, // color_bits_inverted
+ 0x000000, // highlight_color
+ 0x12, // refresh_display_command
+ 1.0, // refresh_time
+ &pin_GPIO5, // busy_pin
+ false, // busy_state
+ 5.0, // seconds_per_frame
+ false, // always_toggle_chip_select
+ true); // grayscale
}
bool board_requests_safe_mode(void) {
diff --git a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c
index 65bc3fb53..40c9e91e4 100644
--- a/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c
+++ b/ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/pins.c
@@ -1,5 +1,7 @@
#include "shared-bindings/board/__init__.h"
+#include "shared-module/displayio/__init__.h"
+
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_GPIO10) },
{ MP_ROM_QSTR(MP_QSTR_AD1), MP_ROM_PTR(&pin_GPIO18) },
@@ -37,5 +39,7 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)}
};
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);
diff --git a/ports/esp32s2/common-hal/displayio/ParallelBus.c b/ports/esp32s2/common-hal/displayio/ParallelBus.c
index 314b72ff7..d0c98f361 100644
--- a/ports/esp32s2/common-hal/displayio/ParallelBus.c
+++ b/ports/esp32s2/common-hal/displayio/ParallelBus.c
@@ -57,7 +57,8 @@ bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
return false;
}
-void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
}
diff --git a/ports/mimxrt10xx/common-hal/displayio/ParallelBus.c b/ports/mimxrt10xx/common-hal/displayio/ParallelBus.c
index 87a72d0f3..0fdf4413b 100644
--- a/ports/mimxrt10xx/common-hal/displayio/ParallelBus.c
+++ b/ports/mimxrt10xx/common-hal/displayio/ParallelBus.c
@@ -57,7 +57,8 @@ bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
return false;
}
-void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
}
diff --git a/ports/nrf/common-hal/displayio/ParallelBus.c b/ports/nrf/common-hal/displayio/ParallelBus.c
index f13e03163..31ee1f48e 100644
--- a/ports/nrf/common-hal/displayio/ParallelBus.c
+++ b/ports/nrf/common-hal/displayio/ParallelBus.c
@@ -141,7 +141,8 @@ bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
}
// This ignores chip_select behaviour because data is clocked in by the write line toggling.
-void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->command, byte_type == DISPLAY_DATA);
uint32_t* clear_write = (uint32_t*) &self->write_group->OUTCLR;
diff --git a/ports/stm/common-hal/displayio/ParallelBus.c b/ports/stm/common-hal/displayio/ParallelBus.c
index 314b72ff7..fd07d38af 100644
--- a/ports/stm/common-hal/displayio/ParallelBus.c
+++ b/ports/stm/common-hal/displayio/ParallelBus.c
@@ -57,7 +57,8 @@ bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
return false;
}
-void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type, display_chip_select_behavior_t chip_select, uint8_t *data, uint32_t data_length) {
+void common_hal_displayio_parallelbus_send(mp_obj_t obj, display_byte_type_t byte_type,
+ display_chip_select_behavior_t chip_select, const uint8_t *data, uint32_t data_length) {
}