Skip to content

Commit f496b6c

Browse files
authored
Merge pull request #2520 from joeycastillo/openbook-squashed
CircuitPython support for the Open Book
2 parents c1ed78d + eb481c9 commit f496b6c

File tree

5 files changed

+221
-0
lines changed

5 files changed

+221
-0
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ jobs:
125125
- "metro_nrf52840_express"
126126
- "mini_sam_m4"
127127
- "monster_m4sk"
128+
- "openbook_m4"
128129
- "particle_argon"
129130
- "particle_boron"
130131
- "particle_xenon"
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2020 Joey Castillo
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#include "boards/board.h"
28+
#include "mpconfigboard.h"
29+
#include "hal/include/hal_gpio.h"
30+
#include "shared-bindings/busio/SPI.h"
31+
#include "shared-bindings/displayio/FourWire.h"
32+
#include "shared-bindings/time/__init__.h"
33+
#include "shared-module/displayio/__init__.h"
34+
#include "shared-module/displayio/mipi_constants.h"
35+
#include "tick.h"
36+
37+
displayio_fourwire_obj_t board_display_obj;
38+
39+
#define DELAY 0x80
40+
#define HEIGHT 400
41+
#define WIDTH 300
42+
43+
uint8_t start_sequence[] = {
44+
0x01, 0x04, 0x03, 0x00, 0x2b, 0x2b, // power setting
45+
0x06, 0x03, 0x17, 0x17, 0x17, // booster soft start
46+
0x04, 0x80, 0xc8, // power on and wait 200 ms
47+
0x00, 0x01, 0x0f, // panel setting
48+
0x61, 0x04, (HEIGHT >> 8) & 0xFF, HEIGHT & 0xFF, (WIDTH >> 8) & 0xFF, WIDTH & 0xFF // Resolution
49+
};
50+
51+
uint8_t stop_sequence[] = {
52+
0x50, 0x01, 0xf7, // CDI setting
53+
0x02, 0x80, 0xf0 // Power off
54+
};
55+
56+
void board_init(void) {
57+
busio_spi_obj_t* spi = &displays[0].fourwire_bus.inline_bus;
58+
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL);
59+
common_hal_busio_spi_never_reset(spi);
60+
61+
displayio_fourwire_obj_t* bus = &displays[0].fourwire_bus;
62+
bus->base.type = &displayio_fourwire_type;
63+
common_hal_displayio_fourwire_construct(bus,
64+
spi,
65+
&pin_PB05, // EPD_DC Command or data
66+
&pin_PB07, // EPD_CS Chip select
67+
&pin_PA00, // EPD_RST Reset
68+
1000000);
69+
70+
displayio_epaperdisplay_obj_t* display = &displays[0].epaper_display;
71+
display->base.type = &displayio_epaperdisplay_type;
72+
common_hal_displayio_epaperdisplay_construct(display,
73+
bus,
74+
start_sequence,
75+
sizeof(start_sequence),
76+
stop_sequence,
77+
sizeof(stop_sequence),
78+
400, // width
79+
300, // height
80+
400, // RAM width
81+
300, // RAM height
82+
0, // colstart
83+
0, // rowstart
84+
0, // rotation
85+
NO_COMMAND, // set_column_window_command
86+
NO_COMMAND, // set_row_window_command
87+
NO_COMMAND, // set_current_column_command
88+
NO_COMMAND, // set_current_row_command
89+
0x13, // write_black_ram_command
90+
false, // black_bits_inverted
91+
NO_COMMAND, // write_color_ram_command (can add this for grayscale eventually)
92+
false, // color_bits_inverted
93+
0x000000, // highlight_color
94+
0x12, // refresh_display_command
95+
40, // refresh_time
96+
&pin_PA01, // busy_pin
97+
false, // busy_state
98+
5, // seconds_per_frame
99+
false); // chip_select (don't always toggle chip select)
100+
}
101+
102+
bool board_requests_safe_mode(void) {
103+
return false;
104+
}
105+
106+
void reset_board(void) {
107+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#define MICROPY_HW_BOARD_NAME "The Open Book Feather"
2+
#define MICROPY_HW_MCU_NAME "samd51j19"
3+
4+
#define CIRCUITPY_MCU_FAMILY samd51
5+
6+
#define MICROPY_HW_LED_STATUS (&pin_PA23)
7+
8+
// These are pins not to reset.
9+
// QSPI Data pins
10+
#define MICROPY_PORT_A (PORT_PA08 | PORT_PA09 | PORT_PA10 | PORT_PA11)
11+
// DotStar pins, QSPI CS, and QSPI SCK
12+
#define MICROPY_PORT_B (PORT_PB10 | PORT_PB11)
13+
#define MICROPY_PORT_C (0)
14+
#define MICROPY_PORT_D (0)
15+
16+
#define DEFAULT_I2C_BUS_SCL (&pin_PA13)
17+
#define DEFAULT_I2C_BUS_SDA (&pin_PA12)
18+
19+
#define DEFAULT_SPI_BUS_SCK (&pin_PA17)
20+
#define DEFAULT_SPI_BUS_MOSI (&pin_PB23)
21+
#define DEFAULT_SPI_BUS_MISO (&pin_PB22)
22+
23+
#define DEFAULT_UART_BUS_RX (&pin_PB17)
24+
#define DEFAULT_UART_BUS_TX (&pin_PB16)
25+
26+
// USB is always used internally so skip the pin objects for it.
27+
#define IGNORE_PIN_PA24 1
28+
#define IGNORE_PIN_PA25 1
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
USB_VID = 0x239A
2+
USB_PID = 0x807E
3+
USB_PRODUCT = "The Open Book Feather"
4+
USB_MANUFACTURER = "Oddly Specific Objects"
5+
6+
CHIP_VARIANT = SAMD51J19A
7+
CHIP_FAMILY = samd51
8+
9+
QSPI_FLASH_FILESYSTEM = 1
10+
EXTERNAL_FLASH_DEVICE_COUNT = 1
11+
EXTERNAL_FLASH_DEVICES = GD25Q16C
12+
LONGINT_IMPL = MPZ
13+
14+
CIRCUITPY_GAMEPADSHIFT = 1
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include "shared-bindings/board/__init__.h"
2+
3+
#include "boards/board.h"
4+
#include "shared-module/displayio/__init__.h"
5+
6+
STATIC const mp_rom_map_elem_t board_global_dict_table[] = {
7+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_PA02) }, // A0 = audio right channel
8+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_PA05) }, // A1 = audio left channel
9+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A2), MP_ROM_PTR(&pin_PB08) },
10+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_PB09) },
11+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A4), MP_ROM_PTR(&pin_PA04) },
12+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A5), MP_ROM_PTR(&pin_PA06) },
13+
14+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A6), MP_ROM_PTR(&pin_PB01) }, // A6 = VBAT Monitor
15+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A7), MP_ROM_PTR(&pin_PB04) }, // A7 = Raw mic input
16+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A8), MP_ROM_PTR(&pin_PB03) }, // A8 = Bottom STEMMA Port
17+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A9), MP_ROM_PTR(&pin_PB02) }, // A9 = Top STEMMA Port
18+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_PA07) }, // A10 = Amplified mic input
19+
{ MP_OBJ_NEW_QSTR(MP_QSTR_A11), MP_ROM_PTR(&pin_PB00) }, // A11 = VBUS Monitor
20+
21+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_PB17) },
22+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D1), MP_ROM_PTR(&pin_PB16) },
23+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D2), MP_ROM_PTR(&pin_PB03) },
24+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D3), MP_ROM_PTR(&pin_PB02) },
25+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D5), MP_ROM_PTR(&pin_PA16) },
26+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D6), MP_ROM_PTR(&pin_PA18) },
27+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D9), MP_ROM_PTR(&pin_PA19) },
28+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D10), MP_ROM_PTR(&pin_PA20) },
29+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_PA21) },
30+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_PA22) },
31+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_PA23) },
32+
{ MP_OBJ_NEW_QSTR(MP_QSTR_D48), MP_ROM_PTR(&pin_PB31) },
33+
34+
// UART
35+
{ MP_OBJ_NEW_QSTR(MP_QSTR_RX), MP_ROM_PTR(&pin_PB17) },
36+
{ MP_OBJ_NEW_QSTR(MP_QSTR_TX), MP_ROM_PTR(&pin_PB16) },
37+
38+
// I2C
39+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_PA12) },
40+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_PA13) },
41+
42+
// SPI
43+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_PA17) },
44+
{ MP_OBJ_NEW_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_PB22) },
45+
{ MP_OBJ_NEW_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_PB23) },
46+
47+
// e-paper SPI and control pins
48+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SCK1), MP_ROM_PTR(&pin_PB13) },
49+
{ MP_OBJ_NEW_QSTR(MP_QSTR_MOSI1), MP_ROM_PTR(&pin_PB15) },
50+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ECS), MP_ROM_PTR(&pin_PB07) },
51+
{ MP_OBJ_NEW_QSTR(MP_QSTR_EDC), MP_ROM_PTR(&pin_PB05) },
52+
{ MP_OBJ_NEW_QSTR(MP_QSTR_ERST), MP_ROM_PTR(&pin_PA00) },
53+
{ MP_OBJ_NEW_QSTR(MP_QSTR_EBSY), MP_ROM_PTR(&pin_PA01) },
54+
55+
// Special named pins
56+
{ MP_OBJ_NEW_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_PA15) },
57+
{ MP_OBJ_NEW_QSTR(MP_QSTR_LOCK_BUTTON), MP_ROM_PTR(&pin_PA27) },
58+
{ MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON_LATCH), MP_ROM_PTR(&pin_PB12) },
59+
{ MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON_OUT), MP_ROM_PTR(&pin_PB30) },
60+
{ MP_OBJ_NEW_QSTR(MP_QSTR_BUTTON_CLOCK), MP_ROM_PTR(&pin_PB14) },
61+
{ MP_OBJ_NEW_QSTR(MP_QSTR_SDCS), MP_ROM_PTR(&pin_PA14) },
62+
{ MP_OBJ_NEW_QSTR(MP_QSTR_MIC_SHUTDOWN), MP_ROM_PTR(&pin_PB31) },
63+
{ MP_OBJ_NEW_QSTR(MP_QSTR_BCS), MP_ROM_PTR(&pin_PB06) }, // BCS = Babel Chip Select, the second flash chip
64+
65+
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
66+
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
67+
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
68+
69+
{ MP_ROM_QSTR(MP_QSTR_DISPLAY), MP_ROM_PTR(&displays[0].epaper_display)}
70+
};
71+
MP_DEFINE_CONST_DICT(board_module_globals, board_global_dict_table);

0 commit comments

Comments
 (0)