Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SAMD51 SPI Secondary Mode #9385

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
639fed2
Add slave_mode parameter to the SPI bus constructor
Randall-Scharpf Nov 7, 2023
b459802
Update SPI construction usages
Randall-Scharpf Nov 7, 2023
58e1ee7
Attempt to change MODE to peripheral
Randall-Scharpf Nov 7, 2023
8444193
fix inversion bitmath error
Randall-Scharpf Dec 4, 2023
b98ff01
add build script
Randall-Scharpf Dec 4, 2023
c969a64
working edits to spi and can attempts
Randall-Scharpf Dec 4, 2023
82a6f95
SPI responds to clock with this change, data transfer still ununcerta…
Randall-Scharpf Dec 6, 2023
9c8401b
build interpreter (mac version)
anniexiang01 Dec 6, 2023
8a552f1
potential fix for busio SPI parameters
anniexiang01 Dec 6, 2023
b983bf9
add SS pin and fix DIPO/DOPO assignment
Randall-Scharpf Apr 2, 2024
1728222
Merge branch '9.0.x' of https://github.com/adafruit/circuitpython int…
Randall-Scharpf Apr 12, 2024
09d2c66
Merge branch 'adafruit-9.0.x' into main
Randall-Scharpf Apr 12, 2024
c06f9e1
hey wait we dont need a crystal
Randall-Scharpf May 4, 2024
bd10666
update dma code to use new allocation interface
Randall-Scharpf May 4, 2024
5490a82
add async spi interface
Randall-Scharpf May 4, 2024
cfa4425
enable preloading data register
Randall-Scharpf May 6, 2024
5c21495
update samd-peripherals submodule to point to a bruinspace-owned fork
Randall-Scharpf May 20, 2024
4d151a0
update reference submodule commit hash
Randall-Scharpf May 20, 2024
26e838b
added board configurations for RAPID-0 CDH, ADCS, and EPS boards. rev…
anniexiang01 May 20, 2024
0ae5be8
corrected board family on rapid0_adcs mpconfigboard.mk file
anniexiang01 May 21, 2024
a73df58
Updated USB VID, PID, and PRODUCT to reflect sublicense given by Micr…
anniexiang01 May 21, 2024
d4df61e
updated adcs board files to be based on the bdmicro vina d51, new bui…
anniexiang01 May 24, 2024
dcc97d7
fixed rapid0-cdh pin error
anniexiang01 May 25, 2024
14136fc
restore metro_m4_express configuration
Randall-Scharpf Jun 30, 2024
555f1a3
remove extraneous build files
Randall-Scharpf Jun 30, 2024
d048667
remove extraneous build files
Randall-Scharpf Jun 30, 2024
4696d07
set SPI drive strength to high
Randall-Scharpf Jul 28, 2024
1fc4d72
haha! adcs works now
Randall-Scharpf Oct 18, 2024
2ba0b56
add annie's new rapid-0 firmware build workflow
Randall-Scharpf Oct 31, 2024
a7b3de4
add SPITarget interface (HAL still unimplemented)
Randall-Scharpf Nov 1, 2024
289f420
implement the spitarget methods
Randall-Scharpf Nov 1, 2024
616ec37
fix the type of self within spitarget
Randall-Scharpf Nov 1, 2024
114d49e
fix import errors and transfer_close return typing
Randall-Scharpf Nov 1, 2024
5657f8a
fix typing and naming mismatches
Randall-Scharpf Nov 1, 2024
1aad399
ok this is the one
Randall-Scharpf Nov 1, 2024
ff2fb90
fix function name mismatch between call and declaration
Randall-Scharpf Nov 1, 2024
dd7056b
return none from bound functions
Randall-Scharpf Nov 1, 2024
1875e70
fix buffer mishandling in spitarget bindings
Randall-Scharpf Nov 5, 2024
0a68f43
remove busio.SPI
Randall-Scharpf Nov 6, 2024
ea344c3
repair constructors referencing old API
Randall-Scharpf Nov 6, 2024
100a045
remove asynchronous interface under busio.SPI
Randall-Scharpf Nov 6, 2024
821b7f2
merge implementation of new spitarget api
Randall-Scharpf Nov 14, 2024
022e191
add missing files not found by wildcard
Randall-Scharpf Nov 14, 2024
d059736
push samd-peripherals to merge commit in adafruit repository
Randall-Scharpf Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bin/
circuitpython-stubs/
test-stubs/
build-*/
build-*

# Test failure outputs
######################
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
url = https://github.com/adafruit/Adafruit_CircuitPython_DotStar.git
[submodule "ports/atmel-samd/peripherals"]
path = ports/atmel-samd/peripherals
url = https://github.com/adafruit/samd-peripherals.git
url = https://github.com/Bruin-Spacecraft-Group/bruinspace-samd-peripherals.git
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make a separate PR to update the Adafruit repo. We'll get that merged in before this PR.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added and sent in a PR, see adafruit/samd-peripherals#46

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR got approved; I've updated the submodule reference to point to the merge commit that just got made

[submodule "frozen/Adafruit_CircuitPython_Crickit"]
path = frozen/Adafruit_CircuitPython_Crickit
url = https://github.com/adafruit/Adafruit_CircuitPython_Crickit
Expand Down
14 changes: 14 additions & 0 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,10 @@ msgstr ""
msgid "Hard fault: memory access or instruction error."
msgstr ""

#: shared-bindings/busio/SPI.c
msgid "Hardware SS pin only supported for slave mode"
msgstr ""

#: ports/mimxrt10xx/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/UART.c ports/stm/common-hal/busio/I2C.c
#: ports/stm/common-hal/busio/SPI.c ports/stm/common-hal/busio/UART.c
Expand Down Expand Up @@ -1339,6 +1343,10 @@ msgstr ""
msgid "Must provide MISO or MOSI pin"
msgstr ""

#: shared-bindings/busio/SPI.c
msgid "Must provide SS pin to operate in slave mode"
msgstr ""

#: shared-bindings/rgbmatrix/RGBMatrix.c
#, c-format
msgid "Must use a multiple of 6 rgb pins, not %d"
Expand Down Expand Up @@ -1883,6 +1891,12 @@ msgstr ""
msgid "Size not supported"
msgstr ""

#: ports/cxd56/common-hal/busio/SPI.c ports/espressif/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/SPI.c ports/nrf/common-hal/busio/SPI.c
#: ports/raspberrypi/common-hal/busio/SPI.c ports/stm/common-hal/busio/SPI.c
msgid "Slave mode SPI is not implemented"
msgstr ""

#: shared-bindings/alarm/SleepMemory.c shared-bindings/memorymap/AddressRange.c
#: shared-bindings/nvm/ByteArray.c
msgid "Slice and value different lengths."
Expand Down
25 changes: 2 additions & 23 deletions ports/atmel-samd/audio_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ static audio_dma_t *audio_dma_state[AUDIO_DMA_CHANNEL_COUNT];
// This cannot be in audio_dma_state because it's volatile.
static volatile bool audio_dma_pending[AUDIO_DMA_CHANNEL_COUNT];

static bool audio_dma_allocated[AUDIO_DMA_CHANNEL_COUNT];

uint8_t find_sync_event_channel_raise() {
uint8_t event_channel = find_sync_event_channel();
if (event_channel >= EVSYS_SYNCH_NUM) {
Expand All @@ -60,24 +58,6 @@ uint8_t find_sync_event_channel_raise() {
return event_channel;
}

uint8_t dma_allocate_channel(void) {
uint8_t channel;
for (channel = 0; channel < AUDIO_DMA_CHANNEL_COUNT; channel++) {
if (!audio_dma_allocated[channel]) {
audio_dma_allocated[channel] = true;
return channel;
}
}
return channel; // i.e., return failure
}

void dma_free_channel(uint8_t channel) {
assert(channel < AUDIO_DMA_CHANNEL_COUNT);
assert(audio_dma_allocated[channel]);
audio_dma_disable_channel(channel);
audio_dma_allocated[channel] = false;
}

void audio_dma_disable_channel(uint8_t channel) {
if (channel >= AUDIO_DMA_CHANNEL_COUNT) {
return;
Expand Down Expand Up @@ -211,7 +191,7 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t *dma,
bool output_signed,
uint32_t output_register_address,
uint8_t dma_trigger_source) {
uint8_t dma_channel = dma_allocate_channel();
uint8_t dma_channel = dma_allocate_channel(true);
if (dma_channel >= AUDIO_DMA_CHANNEL_COUNT) {
return AUDIO_DMA_DMA_BUSY;
}
Expand Down Expand Up @@ -362,8 +342,7 @@ void audio_dma_reset(void) {
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
audio_dma_state[i] = NULL;
audio_dma_pending[i] = false;
audio_dma_allocated[i] = false;
audio_dma_disable_channel(i);
dma_free_channel(i);
dma_descriptor(i)->BTCTRL.bit.VALID = false;
MP_STATE_PORT(playing_audio)[i] = NULL;
}
Expand Down
3 changes: 0 additions & 3 deletions ports/atmel-samd/audio_dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ uint8_t audiosample_channel_count(mp_obj_t sample_obj);
void audio_dma_init(audio_dma_t *dma);
void audio_dma_reset(void);

uint8_t dma_allocate_channel(void);
void dma_free_channel(uint8_t channel);

// This sets everything up but doesn't start the timer.
// Sample is the python object for the sample to play.
// loop is true if we should loop the sample.
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/hallowing_m4_express/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PA01, &pin_PA00, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/monster_m4sk/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA12, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/openbook_m4/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ uint8_t refresh_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/pewpew_lcd/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PA23, &pin_PA22, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/pewpew_m4/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PA13, &pin_PA15, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/pybadge/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/pygamer/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PB13, &pin_PB15, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/boards/seeeduino_wio_terminal/board.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ uint8_t display_init_sequence[] = {
void board_init(void) {
fourwire_fourwire_obj_t *bus = &allocate_display_bus()->fourwire_bus;
busio_spi_obj_t *spi = &bus->inline_bus;
common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, false);
common_hal_busio_spi_construct(spi, &pin_PB20, &pin_PB19, NULL, NULL, false, false);
common_hal_busio_spi_never_reset(spi);

bus->base.type = &fourwire_fourwire_type;
Expand Down
2 changes: 1 addition & 1 deletion ports/atmel-samd/common-hal/audiobusio/PDMIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) {
// output_buffer_length is the number of slots, not the number of bytes.
uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t *self,
uint16_t *output_buffer, uint32_t output_buffer_length) {
uint8_t dma_channel = dma_allocate_channel();
uint8_t dma_channel = dma_allocate_channel(true);
pdmin_event_channel = find_sync_event_channel_raise();
pdmin_dma_block_done = false;

Expand Down
Loading