Rework displays in prep for dynamic support and 8bit parallel.

This commit is contained in:
Scott Shawcroft 2019-01-16 12:04:42 -08:00
parent 076ddfd66b
commit 05d8885a1a
No known key found for this signature in database
GPG Key ID: FD0EDC4B6C53CA59
28 changed files with 817 additions and 318 deletions

5
main.c
View File

@ -27,6 +27,7 @@
#include <stdint.h>
#include <string.h>
#include "shared-module/displayio/__init__.h"
#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
@ -49,6 +50,7 @@
#include "supervisor/port.h"
#include "supervisor/filesystem.h"
#include "supervisor/shared/autoreload.h"
#include "supervisor/shared/board_busses.h"
#include "supervisor/shared/translate.h"
#include "supervisor/shared/rgb_led_status.h"
#include "supervisor/shared/safe_mode.h"
@ -198,10 +200,13 @@ bool run_code_py(safe_mode_t safe_mode) {
serial_write_compressed(translate("WARNING: Your code filename has two extensions\n"));
}
}
// Turn off the display before the heap disappears.
reset_primary_display();
stop_mp();
free_memory(heap);
reset_port();
reset_board_busses();
reset_board();
reset_status_led();

View File

@ -238,7 +238,6 @@ SRC_ASF := $(addprefix asf4/$(CHIP_FAMILY)/, $(SRC_ASF))
SRC_C = \
audio_dma.c \
board_busses.c \
background.c \
fatfs_port.c \
mphalport.c \
@ -307,6 +306,7 @@ SRC_COMMON_HAL = \
digitalio/__init__.c \
digitalio/DigitalInOut.c \
displayio/FourWire.c \
displayio/ParallelBus.c \
i2cslave/__init__.c \
i2cslave/I2CSlave.c \
microcontroller/__init__.c \
@ -379,6 +379,7 @@ SRC_SHARED_MODULE = \
displayio/__init__.c \
displayio/Bitmap.c \
displayio/ColorConverter.c \
displayio/Display.c \
displayio/Group.c \
displayio/OnDiskBitmap.c \
displayio/Palette.c \

View File

@ -33,12 +33,6 @@
#include "py/mpconfig.h"
#ifdef CIRCUITPY_DISPLAYIO
#include "common-hal/displayio/FourWire.h"
extern displayio_fourwire_obj_t board_display_obj;
#endif
// Initializes board related state once on start up.
void board_init(void);

View File

@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2017 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -26,6 +26,13 @@
#include "boards/board.h"
#include "mpconfigboard.h"
#include "hal/include/hal_gpio.h"
#include "shared-bindings/displayio/Display.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-module/displayio/mipi_constants.h"
#include "tick.h"
void board_init(void) {
}

View File

@ -43,3 +43,4 @@
#define IGNORE_PIN_PA25 1
#define CIRCUITPY_I2CSLAVE
#define CIRCUITPY_DISPLAYIO (1)

View File

@ -1,6 +1,7 @@
#include "shared-bindings/board/__init__.h"
#include "board_busses.h"
#include "boards/board.h"
#include "supervisor/shared/board_busses.h"
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) },

View File

@ -25,88 +25,15 @@
*/
#include "boards/board.h"
#include "board_busses.h"
#include "mpconfigboard.h"
#include "hal/include/hal_gpio.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-module/displayio/mipi_constants.h"
#include "shared-module/displayio/__init__.h"
#include "tick.h"
displayio_fourwire_obj_t board_display_obj;
#define DELAY 0x80
uint8_t display_init_sequence[] = {
0xEF, 3, 0x03, 0x80, 0x02,
0xCF, 3, 0x00, 0xC1, 0x30,
0xED, 4, 0x64, 0x03, 0x12, 0x81,
0xE8, 3, 0x85, 0x00, 0x78,
0xCB, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
0xF7, 1, 0x20,
0xEA, 2, 0x00, 0x00,
0xc0, 1, 0x23, // Power control VRH[5:0]
0xc1, 1, 0x10, // Power control SAP[2:0];BT[3:0]
0xc5, 2, 0x3e, 0x28, // VCM control
0xc7, 1, 0x86, // VCM control2
0x36, 1, 0x38, // Memory Access Control
0x37, 1, 0x00, // Vertical scroll zero
0x3a, 1, 0x55, // COLMOD: Pixel Format Set
0xb1, 2, 0x00, 0x18, // Frame Rate Control (In Normal Mode/Full Colors)
0xb6, 3, 0x08, 0x82, 0x27, // Display Function Control
0xF2, 1, 0x00, // 3Gamma Function Disable
0x26, 1, 0x01, // Gamma curve selected
0xe0, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, // Set Gamma
0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
0xe1, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, // Set Gamma
0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
0x11, DELAY, 120, // Exit Sleep
0x29, DELAY, 120, // Display on
};
void board_init(void) {
board_display_obj.base.type = &displayio_fourwire_type;
common_hal_displayio_fourwire_construct(&board_display_obj,
&pin_PA13, // Clock
&pin_PA12, // Data
&pin_PB09, // Command or data
&pin_PB06, // Chip select
&pin_PA00, // Reset
320, // Width
240, // Height
0, // column start
0, // row start
16, // Color depth
MIPI_COMMAND_SET_COLUMN_ADDRESS, // Set column command
MIPI_COMMAND_SET_PAGE_ADDRESS, // Set row command
MIPI_COMMAND_WRITE_MEMORY_START); // Write memory command
uint32_t i = 0;
common_hal_displayio_fourwire_begin_transaction(&board_display_obj);
while (i < sizeof(display_init_sequence)) {
uint8_t *cmd = display_init_sequence + i;
uint8_t data_size = *(cmd + 1);
bool delay = (data_size & DELAY) != 0;
data_size &= ~DELAY;
uint8_t *data = cmd + 2;
common_hal_displayio_fourwire_send(&board_display_obj, true, cmd, 1);
common_hal_displayio_fourwire_send(&board_display_obj, false, data, data_size);
if (delay) {
data_size++;
uint16_t delay_length_ms = *(cmd + 1 + data_size);
if (delay_length_ms == 255) {
delay_length_ms = 500;
}
uint64_t start = ticks_ms;
while (ticks_ms - start < delay_length_ms) {}
} else {
uint64_t start = ticks_ms;
while (ticks_ms - start < 10) {}
}
i += 2 + data_size;
}
common_hal_displayio_fourwire_end_transaction(&board_display_obj);
}
bool board_requests_safe_mode(void) {
@ -114,5 +41,5 @@ bool board_requests_safe_mode(void) {
}
void reset_board(void) {
common_hal_displayio_fourwire_show(&board_display_obj, NULL);
common_hal_displayio_display_show(&primary_display_obj, NULL);
}

View File

@ -65,12 +65,6 @@ void reset_sercoms(void) {
if (sercom_instances[i] == MICROPY_HW_APA102_SERCOM) {
continue;
}
#endif
#ifdef CIRCUITPY_DISPLAYIO
// TODO(tannewt): Make this dynamic.
if (sercom_instances[i] == board_display_obj.bus.spi_desc.dev.prvt) {
continue;
}
#endif
// SWRST is same for all modes of SERCOMs.
sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1;

View File

@ -34,13 +34,11 @@
#include "tick.h"
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
const mcu_pin_obj_t* clock, const mcu_pin_obj_t* data, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint16_t width,
uint16_t height, int16_t colstart, int16_t rowstart, uint16_t color_depth,
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command) {
busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset) {
common_hal_busio_spi_construct(&self->bus, clock, data, mp_const_none);
common_hal_busio_spi_never_reset(&self->bus);
self->bus = spi;
common_hal_busio_spi_never_reset(self->bus);
common_hal_digitalio_digitalinout_construct(&self->command, command);
common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL);
@ -53,93 +51,27 @@ void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
never_reset_pin_number(command->number);
never_reset_pin_number(chip_select->number);
never_reset_pin_number(reset->number);
self->width = width;
self->height = height;
self->color_depth = color_depth;
self->set_column_command = set_column_command;
self->set_row_command = set_row_command;
self->write_ram_command = write_ram_command;
self->current_group = NULL;
self->colstart = colstart;
self->rowstart = rowstart;
}
bool common_hal_displayio_fourwire_begin_transaction(displayio_fourwire_obj_t* self) {
if (!common_hal_busio_spi_try_lock(&self->bus)) {
bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t obj) {
displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
if (!common_hal_busio_spi_try_lock(self->bus)) {
return false;
}
// TODO(tannewt): Stop hardcoding SPI frequency, polarity and phase.
common_hal_busio_spi_configure(&self->bus, 48000000, 0, 0, 8);
common_hal_busio_spi_configure(self->bus, 12000000, 0, 0, 8);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, false);
return true;
}
void common_hal_displayio_fourwire_send(displayio_fourwire_obj_t* self, bool command, uint8_t *data, uint32_t data_length) {
void common_hal_displayio_fourwire_send(mp_obj_t obj, bool command, uint8_t *data, uint32_t data_length) {
displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->command, !command);
common_hal_busio_spi_write(&self->bus, data, data_length);
common_hal_busio_spi_write(self->bus, data, data_length);
}
void common_hal_displayio_fourwire_end_transaction(displayio_fourwire_obj_t* self) {
void common_hal_displayio_fourwire_end_transaction(mp_obj_t obj) {
displayio_fourwire_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, true);
common_hal_busio_spi_unlock(&self->bus);
}
void common_hal_displayio_fourwire_show(displayio_fourwire_obj_t* self, displayio_group_t* root_group) {
self->current_group = root_group;
common_hal_displayio_fourwire_refresh_soon(self);
}
void common_hal_displayio_fourwire_refresh_soon(displayio_fourwire_obj_t* self) {
self->refresh = true;
}
int32_t common_hal_displayio_fourwire_wait_for_frame(displayio_fourwire_obj_t* self) {
uint64_t last_refresh = self->last_refresh;
while (last_refresh == self->last_refresh) {
MICROPY_VM_HOOK_LOOP
}
return 0;
}
void displayio_fourwire_start_region_update(displayio_fourwire_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
// TODO(tannewt): Handle displays with single byte bounds.
common_hal_displayio_fourwire_begin_transaction(self);
uint16_t data[2];
common_hal_displayio_fourwire_send(self, true, &self->set_column_command, 1);
data[0] = __builtin_bswap16(x0 + self->colstart);
data[1] = __builtin_bswap16(x1-1 + self->colstart);
common_hal_displayio_fourwire_send(self, false, (uint8_t*) data, 4);
common_hal_displayio_fourwire_send(self, true, &self->set_row_command, 1);
data[0] = __builtin_bswap16(y0 + 1 + self->rowstart);
data[1] = __builtin_bswap16(y1 + self->rowstart);
common_hal_displayio_fourwire_send(self, false, (uint8_t*) data, 4);
common_hal_displayio_fourwire_send(self, true, &self->write_ram_command, 1);
}
bool displayio_fourwire_send_pixels(displayio_fourwire_obj_t* self, uint32_t* pixels, uint32_t length) {
// TODO: Set this up so its async and 32 bit DMA transfers.
common_hal_displayio_fourwire_send(self, false, (uint8_t*) pixels, length*4);
return true;
}
void displayio_fourwire_finish_region_update(displayio_fourwire_obj_t* self) {
common_hal_displayio_fourwire_end_transaction(self);
}
bool displayio_fourwire_frame_queued(displayio_fourwire_obj_t* self) {
// Refresh at ~30 fps.
return (ticks_ms - self->last_refresh) > 32;
}
bool displayio_fourwire_refresh_queued(displayio_fourwire_obj_t* self) {
return self->refresh || (self->current_group != NULL && displayio_group_needs_refresh(self->current_group));
}
void displayio_fourwire_finish_refresh(displayio_fourwire_obj_t* self) {
if (self->current_group != NULL) {
displayio_group_finish_refresh(self->current_group);
}
self->refresh = false;
self->last_refresh = ticks_ms;
common_hal_busio_spi_unlock(self->bus);
}

View File

@ -33,21 +33,10 @@
typedef struct {
mp_obj_base_t base;
busio_spi_obj_t bus;
busio_spi_obj_t* bus;
digitalio_digitalinout_obj_t command;
digitalio_digitalinout_obj_t chip_select;
digitalio_digitalinout_obj_t reset;
uint16_t width;
uint16_t height;
uint16_t color_depth;
uint8_t set_column_command;
uint8_t set_row_command;
uint8_t write_ram_command;
displayio_group_t *current_group;
bool refresh;
uint64_t last_refresh;
int16_t colstart;
int16_t rowstart;
} displayio_fourwire_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_FOURWIRE_H

View File

@ -0,0 +1,98 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* 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 "shared-bindings/displayio/ParallelBus.h"
#include <stdint.h>
#include "common-hal/microcontroller/Pin.h"
#include "py/runtime.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
#include "tick.h"
void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* self,
const mcu_pin_obj_t* data0, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, const mcu_pin_obj_t* write) {
uint8_t data_pin = data0->number;
if (data_pin % 8 != 0 || data_pin % 32 >= 24) {
mp_raise_ValueError(translate("Data 0 pin must be byte aligned"));
}
for (uint8_t i = 0; i < 8; i++) {
if (!pin_number_is_free(data_pin + i)) {
mp_raise_ValueError_varg(translate("Bus pin %d is already in use"), i);
}
}
PortGroup *const g = &PORT->Group[data0->number % 32];
g->DIRSET.reg = 0xff << data_pin;
self->bus = ((uint8_t*) &g->OUT.reg) + (data0->number % 32 / 8);
self->command.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->command, command);
common_hal_digitalio_digitalinout_switch_to_output(&self->command, true, DRIVE_MODE_PUSH_PULL);
self->chip_select.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->chip_select, chip_select);
common_hal_digitalio_digitalinout_switch_to_output(&self->chip_select, true, DRIVE_MODE_PUSH_PULL);
self->reset.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->reset, reset);
common_hal_digitalio_digitalinout_switch_to_output(&self->reset, true, DRIVE_MODE_PUSH_PULL);
self->write.base.type = &digitalio_digitalinout_type;
common_hal_digitalio_digitalinout_construct(&self->write, write);
common_hal_digitalio_digitalinout_switch_to_output(&self->write, true, DRIVE_MODE_PUSH_PULL);
never_reset_pin_number(command->number);
never_reset_pin_number(chip_select->number);
never_reset_pin_number(reset->number);
never_reset_pin_number(write->number);
for (uint8_t i = 0; i < 8; i++) {
never_reset_pin_number(data_pin + i);
}
}
bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t obj) {
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, false);
return true;
}
void common_hal_displayio_parallelbus_send(mp_obj_t obj, bool command, 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, !command);
for (uint32_t i = 0; i < data_length; i++) {
common_hal_digitalio_digitalinout_set_value(&self->write, false);
*self->bus = data[i];
common_hal_digitalio_digitalinout_set_value(&self->write, true);
}
}
void common_hal_displayio_parallelbus_end_transaction(mp_obj_t obj) {
displayio_parallelbus_obj_t* self = MP_OBJ_TO_PTR(obj);
common_hal_digitalio_digitalinout_set_value(&self->chip_select, true);
}

View File

@ -0,0 +1,41 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* 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 MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_PARALLELBUS_H
#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_PARALLELBUS_H
#include "common-hal/digitalio/DigitalInOut.h"
typedef struct {
mp_obj_base_t base;
uint8_t* bus;
digitalio_digitalinout_obj_t command;
digitalio_digitalinout_obj_t chip_select;
digitalio_digitalinout_obj_t reset;
digitalio_digitalinout_obj_t write;
} displayio_parallelbus_obj_t;
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_DISPLAYIO_PARALLELBUS_H

View File

@ -169,6 +169,20 @@ void claim_pin(const mcu_pin_obj_t* pin) {
#endif
}
bool pin_number_is_free(uint8_t pin_number) {
PortGroup *const port = &PORT->Group[(enum gpio_port)GPIO_PORT(pin_number)];
uint8_t pin_index = GPIO_PIN(pin_number);
volatile PORT_PINCFG_Type *state = &port->PINCFG[pin_index];
volatile PORT_PMUX_Type *pmux = &port->PMUX[pin_index / 2];
if (pin_number == PIN_PA30 || pin_number == PIN_PA31) {
return state->bit.PMUXEN == 1 && ((pmux->reg >> (4 * pin_index % 2)) & 0xf) == 0x6;
}
return state->bit.PMUXEN == 0 && state->bit.INEN == 0 &&
state->bit.PULLEN == 0 && (port->DIR.reg & (1 << pin_index)) == 0;
}
bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
#ifdef MICROPY_HW_NEOPIXEL
if (pin == MICROPY_HW_NEOPIXEL) {
@ -190,15 +204,5 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) {
}
#endif
PortGroup *const port = &PORT->Group[(enum gpio_port)GPIO_PORT(pin->number)];
uint8_t pin_index = GPIO_PIN(pin->number);
volatile PORT_PINCFG_Type *state = &port->PINCFG[pin_index];
volatile PORT_PMUX_Type *pmux = &port->PMUX[pin_index / 2];
if (pin->number == PIN_PA30 || pin->number == PIN_PA31) {
return state->bit.PMUXEN == 1 && ((pmux->reg >> (4 * pin_index % 2)) & 0xf) == 0x6;
}
return state->bit.PMUXEN == 0 && state->bit.INEN == 0 &&
state->bit.PULLEN == 0 && (port->DIR.reg & (1 << pin_index)) == 0;
return pin_number_is_free(pin->number);
}

View File

@ -45,5 +45,6 @@ void reset_all_pins(void);
void reset_pin_number(uint8_t pin_number);
void never_reset_pin_number(uint8_t pin_number);
void claim_pin(const mcu_pin_obj_t* pin);
bool pin_number_is_free(uint8_t pin_number);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_MICROCONTROLLER_PIN_H

View File

@ -60,7 +60,6 @@
#include "samd/external_interrupts.h"
#include "samd/dma.h"
#include "shared-bindings/rtc/__init__.h"
#include "board_busses.h"
#include "reset.h"
#include "tick.h"
@ -226,8 +225,6 @@ void reset_port(void) {
reset_all_pins();
reset_board_busses();
// Output clocks for debugging.
// not supported by SAMD51G; uncomment for SAMD51J or update for 51G
// #ifdef SAMD51

View File

@ -0,0 +1,149 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* 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 "shared-bindings/displayio/Display.h"
#include <stdint.h>
#include "lib/utils/context_manager_helpers.h"
#include "py/binary.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/shared/translate.h"
//| .. currentmodule:: displayio
//|
//| :class:`FourWire` -- Manage updating a display over SPI four wire protocol
//| ==========================================================================
//|
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
//| It doesn't handle display initialization.
//|
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
//|
//| .. class:: Display(display_bus, *, width, height, colstart=0, rowstart=0, color_depth=16,
//| set_column_command=0x2a set_row_command=0x2b, write_ram_command=0x2c)
//|
//| Create a FourWire object associated with the given pins.
//|
STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_color_depth, ARG_set_column_command, ARG_set_row_command, ARG_write_ram_command };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_display_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_init_sequence, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_width, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
{ MP_QSTR_height, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = -1} },
{ MP_QSTR_colstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_rowstart, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} },
{ MP_QSTR_color_depth, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 16} },
{ MP_QSTR_set_column_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2a} },
{ MP_QSTR_set_row_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2b} },
{ MP_QSTR_write_ram_command, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x2c} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_obj_t display_bus = args[ARG_display_bus].u_obj;
mp_int_t width = args[ARG_width].u_int;
mp_int_t height = args[ARG_height].u_int;
if (width == -1 || height == -1) {
mp_raise_ValueError(translate("Width and height kwargs required"));
}
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(args[ARG_init_sequence].u_obj, &bufinfo, MP_BUFFER_READ);
displayio_display_obj_t *self;
if (display_bus == &primary_display.fourwire_bus) {
self = &primary_display.display;
} else {
self = m_new_obj(displayio_display_obj_t);
}
self->base.type = &displayio_display_type;
common_hal_displayio_display_construct(self,
display_bus, width, height, args[ARG_colstart].u_int, args[ARG_rowstart].u_int,
args[ARG_color_depth].u_int, args[ARG_set_column_command].u_int, args[ARG_set_row_command].u_int,
args[ARG_write_ram_command].u_int, bufinfo.buf, bufinfo.len);
return self;
}
//| .. method:: show(group)
//|
//| Switches to displaying the given group of layers.
//|
STATIC mp_obj_t displayio_display_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type);
if (native_layer == MP_OBJ_NULL) {
mp_raise_ValueError(translate("Must be a Group subclass."));
}
displayio_group_t* group = MP_OBJ_TO_PTR(native_layer);
common_hal_displayio_display_show(self, group);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_display_show_obj, displayio_display_obj_show);
//| .. method:: refresh_soon()
//|
//| Queues up a display refresh that happens in the background.
//|
STATIC mp_obj_t displayio_display_obj_refresh_soon(mp_obj_t self_in) {
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_displayio_display_refresh_soon(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_refresh_soon_obj, displayio_display_obj_refresh_soon);
//| .. method:: wait_for_frame()
//|
//| Waits until the next frame has been transmitted to the display unless the wait count is
//| behind the rendered frames. In that case, this will return immediately with the wait count.
//|
STATIC mp_obj_t displayio_display_obj_wait_for_frame(mp_obj_t self_in) {
displayio_display_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_display_wait_for_frame(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_display_wait_for_frame_obj, displayio_display_obj_wait_for_frame);
STATIC const mp_rom_map_elem_t displayio_display_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_display_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_display_refresh_soon_obj) },
{ MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_display_wait_for_frame_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_display_locals_dict, displayio_display_locals_dict_table);
const mp_obj_type_t displayio_display_type = {
{ &mp_type_type },
.name = MP_QSTR_Display,
.make_new = displayio_display_make_new,
.locals_dict = (mp_obj_dict_t*)&displayio_display_locals_dict,
};

View File

@ -0,0 +1,59 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2017, 2018 Scott Shawcroft for Adafruit Industries
*
* 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 MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_DISPLAY_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_DISPLAY_H
#include "common-hal/microcontroller/Pin.h"
#include "shared-module/displayio/Display.h"
#include "shared-module/displayio/Group.h"
extern const mp_obj_type_t displayio_display_type;
#define DELAY 0x80
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height,
int16_t colstart, int16_t rowstart, uint16_t color_depth,
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command,
uint8_t* init_sequence, uint16_t init_sequence_len);
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self);
void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group);
void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self);
void displayio_display_start_region_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void displayio_display_finish_region_update(displayio_display_obj_t* self);
bool displayio_display_frame_queued(displayio_display_obj_t* self);
bool displayio_display_refresh_queued(displayio_display_obj_t* self);
void displayio_display_finish_refresh(displayio_display_obj_t* self);
bool displayio_display_send_pixels(displayio_display_obj_t* self, uint32_t* pixels, uint32_t length);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_DISPLAY_H

View File

@ -3,7 +3,7 @@
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
* Copyright (c) 2018-2019 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -35,6 +35,7 @@
#include "shared-bindings/displayio/Group.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
#include "shared-module/displayio/__init__.h"
#include "supervisor/shared/translate.h"
//| .. currentmodule:: displayio
@ -47,14 +48,44 @@
//|
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
//|
//| .. class:: FourWire(*, clock, data, command, chip_select, width, height, colstart, rowstart,
//| color_depth, set_column_command, set_row_command, write_ram_command)
//| .. class:: FourWire(spi_bus, *, command, chip_select, reset)
//|
//| Create a FourWire object associated with the given pins.
//|
STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
return mp_const_none;
enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset };
static const mp_arg_t allowed_args[] = {
{ MP_QSTR_spi_bus, MP_ARG_REQUIRED | MP_ARG_OBJ },
{ MP_QSTR_command, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_chip_select, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
{ MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} },
};
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
mp_obj_t command = args[ARG_command].u_obj;
mp_obj_t chip_select = args[ARG_chip_select].u_obj;
mp_obj_t reset = args[ARG_reset].u_obj;
if (command == mp_const_none || chip_select == mp_const_none) {
mp_raise_ValueError(translate("Command and chip_select required"));
}
displayio_fourwire_obj_t* self;
mp_obj_t spi = args[ARG_spi_bus].u_obj;
if (board_spi() == spi && primary_display.bus_type == NULL) {
self = &primary_display.fourwire_bus;
primary_display.bus_type = &displayio_fourwire_type;
} else {
// TODO(tannewt): Always check pin free. For now we ignore the primary display.
assert_pin_free(command);
assert_pin_free(chip_select);
assert_pin_free(reset);
self = m_new_obj(displayio_fourwire_obj_t);
}
common_hal_displayio_fourwire_construct(self,
MP_OBJ_TO_PTR(spi), command, chip_select, reset);
return self;
}
@ -68,50 +99,8 @@ STATIC mp_obj_t displayio_fourwire_obj_send(size_t n_args, const mp_obj_t *pos_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_fourwire_send_obj, 1, displayio_fourwire_obj_send);
//| .. method:: show(group)
//|
//| Switches do displaying the given group of elements.
//|
STATIC mp_obj_t displayio_fourwire_obj_show(mp_obj_t self_in, mp_obj_t group_in) {
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_obj_t native_layer = mp_instance_cast_to_native_base(group_in, &displayio_group_type);
if (native_layer == MP_OBJ_NULL) {
mp_raise_ValueError(translate("Must be a Group subclass."));
}
displayio_group_t* group = MP_OBJ_TO_PTR(native_layer);
common_hal_displayio_fourwire_show(self, group);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_2(displayio_fourwire_show_obj, displayio_fourwire_obj_show);
//| .. method:: refresh_soon()
//|
//| Queues up a display refresh that happens in the background.
//|
STATIC mp_obj_t displayio_fourwire_obj_refresh_soon(mp_obj_t self_in) {
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_displayio_fourwire_refresh_soon(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_refresh_soon_obj, displayio_fourwire_obj_refresh_soon);
//| .. method:: wait_for_frame()
//|
//| Waits until the next frame has been transmitted to the display unless the wait count is
//| behind the rendered frames. In that case, this will return immediately with the wait count.
//|
STATIC mp_obj_t displayio_fourwire_obj_wait_for_frame(mp_obj_t self_in) {
displayio_fourwire_obj_t *self = MP_OBJ_TO_PTR(self_in);
return MP_OBJ_NEW_SMALL_INT(common_hal_displayio_fourwire_wait_for_frame(self));
}
MP_DEFINE_CONST_FUN_OBJ_1(displayio_fourwire_wait_for_frame_obj, displayio_fourwire_obj_wait_for_frame);
STATIC const mp_rom_map_elem_t displayio_fourwire_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_fourwire_send_obj) },
{ MP_ROM_QSTR(MP_QSTR_show), MP_ROM_PTR(&displayio_fourwire_show_obj) },
{ MP_ROM_QSTR(MP_QSTR_refresh_soon), MP_ROM_PTR(&displayio_fourwire_refresh_soon_obj) },
{ MP_ROM_QSTR(MP_QSTR_wait_for_frame), MP_ROM_PTR(&displayio_fourwire_wait_for_frame_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_fourwire_locals_dict, displayio_fourwire_locals_dict_table);

View File

@ -31,35 +31,18 @@
#include "common-hal/microcontroller/Pin.h"
#include "shared-module/displayio/Group.h"
#include "supervisor/shared/board_busses.h"
extern const mp_obj_type_t displayio_fourwire_type;
// TODO(tannewt): Split this apart into FourWire and a Display object because the dimensions and
// commands are also used for the parallel buses.
void common_hal_displayio_fourwire_construct(displayio_fourwire_obj_t* self,
const mcu_pin_obj_t* clock, const mcu_pin_obj_t* data, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, uint16_t width, uint16_t height,
int16_t colstart, int16_t rowstart, uint16_t color_depth,
uint8_t set_column_command, uint8_t set_row_command, uint8_t write_ram_command);
busio_spi_obj_t* spi, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset);
int32_t common_hal_displayio_fourwire_wait_for_frame(displayio_fourwire_obj_t* self);
bool common_hal_displayio_fourwire_begin_transaction(mp_obj_t self);
bool common_hal_displayio_fourwire_begin_transaction(displayio_fourwire_obj_t* self);
void common_hal_displayio_fourwire_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
void common_hal_displayio_fourwire_send(displayio_fourwire_obj_t* self, bool command, uint8_t *data, uint32_t data_length);
void common_hal_displayio_fourwire_end_transaction(displayio_fourwire_obj_t* self);
void common_hal_displayio_fourwire_show(displayio_fourwire_obj_t* self, displayio_group_t* root_group);
void common_hal_displayio_fourwire_refresh_soon(displayio_fourwire_obj_t* self);
void displayio_fourwire_start_region_update(displayio_fourwire_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
void displayio_fourwire_finish_region_update(displayio_fourwire_obj_t* self);
bool displayio_fourwire_frame_queued(displayio_fourwire_obj_t* self);
bool displayio_fourwire_refresh_queued(displayio_fourwire_obj_t* self);
void displayio_fourwire_finish_refresh(displayio_fourwire_obj_t* self);
bool displayio_fourwire_send_pixels(displayio_fourwire_obj_t* self, uint32_t* pixels, uint32_t length);
void common_hal_displayio_fourwire_end_transaction(mp_obj_t self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_FOURWIRE_H

View File

@ -0,0 +1,79 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* 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 "shared-bindings/displayio/ParallelBus.h"
#include <stdint.h>
#include "lib/utils/context_manager_helpers.h"
#include "py/binary.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/util.h"
#include "supervisor/shared/translate.h"
//| .. currentmodule:: displayio
//|
//| :class:`ParallelBus` -- Manage updating a display over SPI four wire protocol
//| ==========================================================================
//|
//| Manage updating a display over SPI four wire protocol in the background while Python code runs.
//| It doesn't handle display initialization.
//|
//| .. warning:: This will be changed before 4.0.0. Consider it very experimental.
//|
//| .. class:: ParallelBus(*, data0, command, chip_select, reset, write, bus_width=8)
//|
//| Create a ParallelBus object associated with the given pins.
//|
STATIC mp_obj_t displayio_parallelbus_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
return mp_const_none;
}
//| .. method:: send(command, data)
//|
//|
STATIC mp_obj_t displayio_parallelbus_obj_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_raise_NotImplementedError(translate("displayio is a work in progress"));
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_KW(displayio_parallelbus_send_obj, 1, displayio_parallelbus_obj_send);
STATIC const mp_rom_map_elem_t displayio_parallelbus_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&displayio_parallelbus_send_obj) },
};
STATIC MP_DEFINE_CONST_DICT(displayio_parallelbus_locals_dict, displayio_parallelbus_locals_dict_table);
const mp_obj_type_t displayio_parallelbus_type = {
{ &mp_type_type },
.name = MP_QSTR_ParallelBus,
.make_new = displayio_parallelbus_make_new,
.locals_dict = (mp_obj_dict_t*)&displayio_parallelbus_locals_dict,
};

View File

@ -0,0 +1,47 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* 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 MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_PARALLELBUS_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_PARALLELBUS_H
#include "common-hal/displayio/ParallelBus.h"
#include "common-hal/microcontroller/Pin.h"
#include "shared-module/displayio/Group.h"
extern const mp_obj_type_t displayio_parallelbus_type;
void common_hal_displayio_parallelbus_construct(displayio_parallelbus_obj_t* self,
const mcu_pin_obj_t* data0, const mcu_pin_obj_t* command,
const mcu_pin_obj_t* chip_select, const mcu_pin_obj_t* reset, const mcu_pin_obj_t* write);
bool common_hal_displayio_parallelbus_begin_transaction(mp_obj_t self);
void common_hal_displayio_parallelbus_send(mp_obj_t self, bool command, uint8_t *data, uint32_t data_length);
void common_hal_displayio_parallelbus_end_transaction(mp_obj_t self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYBUSIO_PARALLELBUS_H

View File

@ -0,0 +1,149 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2018 Scott Shawcroft for Adafruit Industries
*
* 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 "shared-bindings/displayio/Display.h"
#include "py/runtime.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-bindings/displayio/ParallelBus.h"
#include <stdint.h>
#include "tick.h"
#define DELAY 0x80
void common_hal_displayio_display_construct(displayio_display_obj_t* self,
mp_obj_t bus, uint16_t width, uint16_t height, int16_t colstart, int16_t rowstart,
uint16_t color_depth, uint8_t set_column_command, uint8_t set_row_command,
uint8_t write_ram_command, uint8_t* init_sequence, uint16_t init_sequence_len) {
self->width = width;
self->height = height;
self->color_depth = color_depth;
self->set_column_command = set_column_command;
self->set_row_command = set_row_command;
self->write_ram_command = write_ram_command;
self->current_group = NULL;
self->colstart = colstart;
self->rowstart = rowstart;
if (MP_OBJ_IS_TYPE(bus, &displayio_parallelbus_type)) {
self->begin_transaction = common_hal_displayio_parallelbus_begin_transaction;
self->send = common_hal_displayio_parallelbus_send;
self->end_transaction = common_hal_displayio_parallelbus_end_transaction;
} else if (MP_OBJ_IS_TYPE(bus, &displayio_fourwire_type)) {
self->begin_transaction = common_hal_displayio_fourwire_begin_transaction;
self->send = common_hal_displayio_fourwire_send;
self->end_transaction = common_hal_displayio_fourwire_end_transaction;
} else {
mp_raise_ValueError(translate("Unsupported display bus type"));
}
self->bus = bus;
uint32_t i = 0;
self->begin_transaction(self->bus);
while (i < init_sequence_len) {
uint8_t *cmd = init_sequence + i;
uint8_t data_size = *(cmd + 1);
bool delay = (data_size & DELAY) != 0;
data_size &= ~DELAY;
uint8_t *data = cmd + 2;
self->send(self->bus, true, cmd, 1);
self->send(self->bus, false, data, data_size);
if (delay) {
data_size++;
uint16_t delay_length_ms = *(cmd + 1 + data_size);
if (delay_length_ms == 255) {
delay_length_ms = 500;
}
uint64_t start = ticks_ms;
while (ticks_ms - start < delay_length_ms) {}
} else {
uint64_t start = ticks_ms;
while (ticks_ms - start < 10) {}
}
i += 2 + data_size;
}
self->end_transaction(self->bus);
}
void common_hal_displayio_display_show(displayio_display_obj_t* self, displayio_group_t* root_group) {
self->current_group = root_group;
common_hal_displayio_display_refresh_soon(self);
}
void common_hal_displayio_display_refresh_soon(displayio_display_obj_t* self) {
self->refresh = true;
}
int32_t common_hal_displayio_display_wait_for_frame(displayio_display_obj_t* self) {
uint64_t last_refresh = self->last_refresh;
while (last_refresh == self->last_refresh) {
MICROPY_VM_HOOK_LOOP
}
return 0;
}
void displayio_display_start_region_update(displayio_display_obj_t* self, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
// TODO(tannewt): Handle displays with single byte bounds.
self->begin_transaction(self->bus);
uint16_t data[2];
self->send(self->bus, true, &self->set_column_command, 1);
data[0] = __builtin_bswap16(x0 + self->colstart);
data[1] = __builtin_bswap16(x1 + self->colstart);
self->send(self->bus, false, (uint8_t*) data, 4);
self->send(self->bus, true, &self->set_row_command, 1);
data[0] = __builtin_bswap16(y0 + self->rowstart);
data[1] = __builtin_bswap16(y1 + self->rowstart);
self->send(self->bus, false, (uint8_t*) data, 4);
self->send(self->bus, true, &self->write_ram_command, 1);
}
void displayio_display_finish_region_update(displayio_display_obj_t* self) {
self->end_transaction(self->bus);
}
bool displayio_display_frame_queued(displayio_display_obj_t* self) {
// Refresh at ~30 fps.
return (ticks_ms - self->last_refresh) > 32;
}
bool displayio_display_refresh_queued(displayio_display_obj_t* self) {
return self->refresh || (self->current_group != NULL && displayio_group_needs_refresh(self->current_group));
}
void displayio_display_finish_refresh(displayio_display_obj_t* self) {
if (self->current_group != NULL) {
displayio_group_finish_refresh(self->current_group);
}
self->refresh = false;
self->last_refresh = ticks_ms;
}
bool displayio_display_send_pixels(displayio_display_obj_t* self, uint32_t* pixels, uint32_t length) {
self->send(self->bus, false, (uint8_t*) pixels, length * 4);
return true;
}

View File

@ -0,0 +1,55 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2019 Scott Shawcroft for Adafruit Industries
*
* 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 MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_DISPLAY_H
#define MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_DISPLAY_H
#include "shared-module/displayio/Group.h"
typedef bool (*display_bus_begin_transaction)(mp_obj_t bus);
typedef void (*display_bus_send)(mp_obj_t bus, bool command, uint8_t *data, uint32_t data_length);
typedef void (*display_bus_end_transaction)(mp_obj_t bus);
typedef struct {
mp_obj_base_t base;
mp_obj_t bus;
uint16_t width;
uint16_t height;
uint16_t color_depth;
uint8_t set_column_command;
uint8_t set_row_command;
uint8_t write_ram_command;
displayio_group_t *current_group;
bool refresh;
uint64_t last_refresh;
int16_t colstart;
int16_t rowstart;
display_bus_begin_transaction begin_transaction;
display_bus_send send;
display_bus_end_transaction end_transaction;
} displayio_display_obj_t;
#endif // MICROPY_INCLUDED_SHARED_MODULE_DISPLAYIO_DISPLAY_H

View File

@ -1,44 +1,17 @@
#include "shared-bindings/displayio/FourWire.h"
extern displayio_fourwire_obj_t board_display_obj;
#include "shared-module/displayio/__init__.h"
void start_region_update(displayio_fourwire_obj_t* display, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
// TODO delegate between different display types
displayio_fourwire_start_region_update(display, x0, y0, x1, y1);
}
#include "shared-bindings/displayio/Display.h"
void finish_region_update(displayio_fourwire_obj_t* display) {
// TODO delegate between different display types
displayio_fourwire_finish_region_update(display);
}
void finish_refresh(displayio_fourwire_obj_t* display) {
// TODO delegate between different display types
displayio_fourwire_finish_refresh(display);
}
bool frame_queued(displayio_fourwire_obj_t* display) {
// TODO delegate between different display types
return displayio_fourwire_frame_queued(display);
}
bool refresh_queued(displayio_fourwire_obj_t* display) {
// TODO delegate between different display types
return displayio_fourwire_refresh_queued(display);
}
bool send_pixels(displayio_fourwire_obj_t* display, uint32_t* pixels, uint32_t length) {
// TODO delegate between different display types
return displayio_fourwire_send_pixels(display, pixels, length);
}
primary_display_t primary_display;
void displayio_refresh_display(void) {
displayio_fourwire_obj_t* display = &board_display_obj;
displayio_display_obj_t* display = &primary_display.display;
if (!frame_queued(display)) {
if (!displayio_display_frame_queued(display)) {
return;
}
if (refresh_queued(display)) {
if (displayio_display_refresh_queued(display)) {
PORT->Group[1].DIRSET.reg = 1 << 22;
// We compute the pixels
@ -50,7 +23,7 @@ void displayio_refresh_display(void) {
//size_t row_size = (x1 - x0);
uint16_t buffer_size = 256;
uint32_t buffer[buffer_size / 2];
start_region_update(display, x0, y0, x1, y1);
displayio_display_start_region_update(display, x0, y0, x1, y1);
for (uint16_t y = y0; y < y1; ++y) {
for (uint16_t x = x0; x < x1; ++x) {
uint16_t* pixel = &(((uint16_t*)buffer)[index]);
@ -72,8 +45,8 @@ void displayio_refresh_display(void) {
index += 1;
// The buffer is full, send it.
if (index >= buffer_size) {
if (!send_pixels(display, buffer, buffer_size / 2)) {
finish_region_update(display);
if (!displayio_display_send_pixels(display, buffer, buffer_size / 2)) {
displayio_display_finish_region_update(display);
return;
}
index = 0;
@ -81,11 +54,15 @@ void displayio_refresh_display(void) {
}
}
// Send the remaining data.
if (index && !send_pixels(display, buffer, index * 2)) {
finish_region_update(display);
if (index && !displayio_display_send_pixels(display, buffer, index * 2)) {
displayio_display_finish_region_update(display);
return;
}
finish_region_update(display);
displayio_display_finish_region_update(display);
}
finish_refresh(display);
displayio_display_finish_refresh(display);
}
void reset_primary_display(void) {
common_hal_displayio_display_show(&primary_display.display, NULL);
}

View File

@ -27,6 +27,22 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
#define MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H
#include "shared-bindings/displayio/Display.h"
#include "shared-bindings/displayio/FourWire.h"
#include "shared-bindings/displayio/ParallelBus.h"
typedef struct {
union {
displayio_fourwire_obj_t fourwire_bus;
displayio_parallelbus_obj_t parallel_bus;
};
mp_const_obj_t bus_type;
displayio_display_obj_t display;
} primary_display_t;
extern primary_display_t primary_display;
void displayio_refresh_display(void);
void reset_primary_display(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_DISPLAYIO___INIT___H

View File

@ -63,11 +63,12 @@ STATIC mp_obj_t board_i2c(void) {
MP_DEFINE_CONST_FUN_OBJ_0(board_i2c_obj, board_i2c);
#if BOARD_SPI
STATIC busio_spi_obj_t spi_obj;
STATIC mp_obj_t spi_singleton = NULL;
STATIC mp_obj_t board_spi(void) {
mp_obj_t board_spi(void) {
if (spi_singleton == NULL) {
busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t);
busio_spi_obj_t *self = &spi_obj;
self->base.type = &busio_spi_type;
assert_pin_free(DEFAULT_SPI_BUS_SCK);
assert_pin_free(DEFAULT_SPI_BUS_MOSI);
@ -81,7 +82,7 @@ STATIC mp_obj_t board_spi(void) {
return spi_singleton;
}
#else
STATIC mp_obj_t board_spi(void) {
mp_obj_t board_spi(void) {
mp_raise_NotImplementedError(translate("No default SPI bus"));
return NULL;
}

View File

@ -24,18 +24,20 @@
* THE SOFTWARE.
*/
#ifndef MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H
#define MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H
#ifndef MICROPY_INCLUDED_SUPERVISOR_SHARED_BOARD_BUSSES_H
#define MICROPY_INCLUDED_SUPERVISOR_SHARED_BOARD_BUSSES_H
void board_i2c(void);
#include "py/obj.h"
mp_obj_t board_i2c(void);
extern mp_obj_fun_builtin_fixed_t board_i2c_obj;
void board_spi(void);
mp_obj_t board_spi(void);
extern mp_obj_fun_builtin_fixed_t board_spi_obj;
void board_uart(void);
mp_obj_t board_uart(void);
extern mp_obj_fun_builtin_fixed_t board_uart_obj;
void reset_board_busses(void);
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BOARD_BUSSES_H
#endif // MICROPY_INCLUDED_SUPERVISOR_SHARED_BOARD_BUSSES_H

View File

@ -2,6 +2,7 @@ SRC_SUPERVISOR = \
main.c \
supervisor/port.c \
supervisor/shared/autoreload.c \
supervisor/shared/board_busses.c \
supervisor/shared/filesystem.c \
supervisor/shared/flash.c \
supervisor/shared/micropython.c \