3434void common_hal_busio_spi_construct (busio_spi_obj_t * self ,
3535 const mcu_pin_obj_t * clock , const mcu_pin_obj_t * mosi ,
3636 const mcu_pin_obj_t * miso ) {
37- // Sercom* sercom = NULL;
38- // uint8_t sercom_index;
39- // uint32_t clock_pinmux = 0;
40- // bool mosi_none = mosi == mp_const_none || mosi == NULL;
41- // bool miso_none = miso == mp_const_none || miso == NULL;
42- // uint32_t mosi_pinmux = 0;
43- // uint32_t miso_pinmux = 0;
44- // uint8_t clock_pad = 0;
45- // uint8_t mosi_pad = 0;
46- // uint8_t miso_pad = 0;
47- // uint8_t dopo = 255;
48-
49- // // Special case for SAMR boards.
50- // #ifdef PIN_PC19
51- // if (miso == &pin_PC19) {
52- // if (mosi == &pin_PB30 && clock == &pin_PC18) {
53- // sercom = SERCOM4;
54- // sercom_index = 4;
55- // clock_pinmux = MUX_F;
56- // mosi_pinmux = MUX_F;
57- // miso_pinmux = MUX_F;
58- // clock_pad = 3;
59- // mosi_pad = 2;
60- // miso_pad = 0;
61- // dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad);
62- // }
63- // // Error, leave SERCOM unset to throw an exception later.
64- // } else {
65- // #endif
66- // for (int i = 0; i < NUM_SERCOMS_PER_PIN; i++) {
67- // sercom_index = clock->sercom[i].index; // 2 for SERCOM2, etc.
68- // if (sercom_index >= SERCOM_INST_NUM) {
69- // continue;
70- // }
71- // Sercom* potential_sercom = sercom_insts[sercom_index];
72- // if (
73- // #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102)
74- // (potential_sercom->SPI.CTRLA.bit.ENABLE != 0 &&
75- // potential_sercom != status_apa102.spi_desc.dev.prvt &&
76- // !apa102_sck_in_use)) {
77- // #else
78- // potential_sercom->SPI.CTRLA.bit.ENABLE != 0) {
79- // #endif
80- // continue;
81- // }
82- // clock_pinmux = PINMUX(clock->number, (i == 0) ? MUX_C : MUX_D);
83- // clock_pad = clock->sercom[i].pad;
84- // if (!samd_peripherals_valid_spi_clock_pad(clock_pad)) {
85- // continue;
86- // }
87- // for (int j = 0; j < NUM_SERCOMS_PER_PIN; j++) {
88- // if (!mosi_none) {
89- // if (sercom_index == mosi->sercom[j].index) {
90- // mosi_pinmux = PINMUX(mosi->number, (j == 0) ? MUX_C : MUX_D);
91- // mosi_pad = mosi->sercom[j].pad;
92- // dopo = samd_peripherals_get_spi_dopo(clock_pad, mosi_pad);
93- // if (dopo > 0x3) {
94- // continue; // pad combination not possible
95- // }
96- // if (miso_none) {
97- // sercom = potential_sercom;
98- // break;
99- // }
100- // } else {
101- // continue;
102- // }
103- // }
104- // if (!miso_none) {
105- // for (int k = 0; k < NUM_SERCOMS_PER_PIN; k++) {
106- // if (sercom_index == miso->sercom[k].index) {
107- // miso_pinmux = PINMUX(miso->number, (k == 0) ? MUX_C : MUX_D);
108- // miso_pad = miso->sercom[k].pad;
109- // sercom = potential_sercom;
110- // break;
111- // }
112- // }
113- // }
114- // if (sercom != NULL) {
115- // break;
116- // }
117- // }
118- // if (sercom != NULL) {
119- // break;
120- // }
121- // }
122- // #ifdef PIN_PC19
123- // }
124- // #endif
125- // if (sercom == NULL) {
126- // mp_raise_ValueError(translate("Invalid pins"));
127- // }
128-
129- // // Set up SPI clocks on SERCOM.
130- // samd_peripherals_sercom_clock_init(sercom, sercom_index);
131-
132- // #if defined(MICROPY_HW_APA102_SCK) && defined(MICROPY_HW_APA102_MOSI) && !defined(CIRCUITPY_BITBANG_APA102)
133- // // if we're re-using the dotstar sercom, make sure it is disabled or the init will fail out
134- // hri_sercomspi_clear_CTRLA_ENABLE_bit(sercom);
135- // #endif
136- // if (spi_m_sync_init(&self->spi_desc, sercom) != ERR_NONE) {
137- // mp_raise_OSError(MP_EIO);
138- // }
139-
140- // // Pads must be set after spi_m_sync_init(), which uses default values from
141- // // the prototypical SERCOM.
142- // hri_sercomspi_write_CTRLA_DOPO_bf(sercom, dopo);
143- // hri_sercomspi_write_CTRLA_DIPO_bf(sercom, miso_pad);
144-
145- // // Always start at 250khz which is what SD cards need. They are sensitive to
146- // // SPI bus noise before they are put into SPI mode.
147- // uint8_t baud_value = samd_peripherals_spi_baudrate_to_baud_reg_value(250000);
148- // if (spi_m_sync_set_baudrate(&self->spi_desc, baud_value) != ERR_NONE) {
149- // // spi_m_sync_set_baudrate does not check for validity, just whether the device is
150- // // busy or not
151- // mp_raise_OSError(MP_EIO);
152- // }
153-
154- // gpio_set_pin_direction(clock->number, GPIO_DIRECTION_OUT);
155- // gpio_set_pin_pull_mode(clock->number, GPIO_PULL_OFF);
156- // gpio_set_pin_function(clock->number, clock_pinmux);
157- // claim_pin(clock);
158- // self->clock_pin = clock->number;
159-
160- // if (mosi_none) {
161- // self->MOSI_pin = NO_PIN;
162- // } else {
163- // gpio_set_pin_direction(mosi->number, GPIO_DIRECTION_OUT);
164- // gpio_set_pin_pull_mode(mosi->number, GPIO_PULL_OFF);
165- // gpio_set_pin_function(mosi->number, mosi_pinmux);
166- // self->MOSI_pin = mosi->number;
167- // claim_pin(mosi);
168- // }
169-
170- // if (miso_none) {
171- // self->MISO_pin = NO_PIN;
172- // } else {
173- // gpio_set_pin_direction(miso->number, GPIO_DIRECTION_IN);
174- // gpio_set_pin_pull_mode(miso->number, GPIO_PULL_OFF);
175- // gpio_set_pin_function(miso->number, miso_pinmux);
176- // self->MISO_pin = miso->number;
177- // claim_pin(miso);
178- // }
179-
180- // spi_m_sync_enable(&self->spi_desc);
18137}
18238
18339void common_hal_busio_spi_never_reset (busio_spi_obj_t * self ) {
184- // never_reset_sercom(self->spi_desc.dev.prvt);
185-
186- // never_reset_pin_number(self->clock_pin);
187- // never_reset_pin_number(self->MOSI_pin);
188- // never_reset_pin_number(self->MISO_pin);
18940}
19041
19142bool common_hal_busio_spi_deinited (busio_spi_obj_t * self ) {
192- //return self->clock_pin == NO_PIN;
19343}
19444
19545void common_hal_busio_spi_deinit (busio_spi_obj_t * self ) {
196- // if (common_hal_busio_spi_deinited(self)) {
197- // return;
198- // }
199- // allow_reset_sercom(self->spi_desc.dev.prvt);
200-
201- // spi_m_sync_disable(&self->spi_desc);
202- // spi_m_sync_deinit(&self->spi_desc);
203- // reset_pin_number(self->clock_pin);
204- // reset_pin_number(self->MOSI_pin);
205- // reset_pin_number(self->MISO_pin);
206- // self->clock_pin = NO_PIN;
20746}
20847
20948bool common_hal_busio_spi_configure (busio_spi_obj_t * self ,
21049 uint32_t baudrate , uint8_t polarity , uint8_t phase , uint8_t bits ) {
211- // uint8_t baud_reg_value = samd_peripherals_spi_baudrate_to_baud_reg_value(baudrate);
212-
213- // void * hw = self->spi_desc.dev.prvt;
214- // // If the settings are already what we want then don't reset them.
215- // if (hri_sercomspi_get_CTRLA_CPHA_bit(hw) == phase &&
216- // hri_sercomspi_get_CTRLA_CPOL_bit(hw) == polarity &&
217- // hri_sercomspi_read_CTRLB_CHSIZE_bf(hw) == ((uint32_t)bits - 8) &&
218- // hri_sercomspi_read_BAUD_BAUD_bf(hw) == baud_reg_value) {
219- // return true;
220- // }
221-
222- // // Disable, set values (most or all are enable-protected), and re-enable.
223- // spi_m_sync_disable(&self->spi_desc);
224- // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK);
225-
226- // hri_sercomspi_write_CTRLA_CPHA_bit(hw, phase);
227- // hri_sercomspi_write_CTRLA_CPOL_bit(hw, polarity);
228- // hri_sercomspi_write_CTRLB_CHSIZE_bf(hw, bits - 8);
229- // hri_sercomspi_write_BAUD_BAUD_bf(hw, baud_reg_value);
230- // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK);
231-
232- // spi_m_sync_enable(&self->spi_desc);
233- // hri_sercomspi_wait_for_sync(hw, SERCOM_SPI_SYNCBUSY_MASK);
234-
23550 return true;
23651}
23752
23853bool common_hal_busio_spi_try_lock (busio_spi_obj_t * self ) {
23954 bool grabbed_lock = false;
240- // CRITICAL_SECTION_ENTER()
241- // if (!self->has_lock) {
242- // grabbed_lock = true;
243- // self->has_lock = true;
244- // }
245- // CRITICAL_SECTION_LEAVE();
24655 return grabbed_lock ;
24756}
24857
@@ -256,66 +65,25 @@ void common_hal_busio_spi_unlock(busio_spi_obj_t *self) {
25665
25766bool common_hal_busio_spi_write (busio_spi_obj_t * self ,
25867 const uint8_t * data , size_t len ) {
259- // if (len == 0) {
260- // return true;
261- // }
262- // int32_t status;
263- // if (len >= 16) {
264- // status = sercom_dma_write(self->spi_desc.dev.prvt, data, len);
265- // } else {
266- // struct io_descriptor *spi_io;
267- // spi_m_sync_get_io_descriptor(&self->spi_desc, &spi_io);
268- // status = spi_io->write(spi_io, data, len);
269- // }
270- return 0 ;//status >= 0; // Status is number of chars read or an error code < 0.
68+ return 0 ;
27169}
27270
27371bool common_hal_busio_spi_read (busio_spi_obj_t * self ,
27472 uint8_t * data , size_t len , uint8_t write_value ) {
275- // if (len == 0) {
276- // return true;
277- // }
278- // int32_t status;
279- // if (len >= 16) {
280- // status = sercom_dma_read(self->spi_desc.dev.prvt, data, len, write_value);
281- // } else {
282- // self->spi_desc.dev.dummy_byte = write_value;
283-
284- // struct io_descriptor *spi_io;
285- // spi_m_sync_get_io_descriptor(&self->spi_desc, &spi_io);
286-
287- // status = spi_io->read(spi_io, data, len);
288- // }
289- return 0 ;//status >= 0; // Status is number of chars read or an error code < 0.
73+ return 0 ;
29074}
29175
29276bool common_hal_busio_spi_transfer (busio_spi_obj_t * self , uint8_t * data_out , uint8_t * data_in , size_t len ) {
293- // if (len == 0) {
294- // return true;
295- // }
296- // int32_t status;
297- // if (len >= 16) {
298- // status = sercom_dma_transfer(self->spi_desc.dev.prvt, data_out, data_in, len);
299- // } else {
300- // struct spi_xfer xfer;
301- // xfer.txbuf = data_out;
302- // xfer.rxbuf = data_in;
303- // xfer.size = len;
304- // status = spi_m_sync_transfer(&self->spi_desc, &xfer);
305- // }
306- return 0 ;//status >= 0; // Status is number of chars read or an error code < 0.
77+ return 0 ;
30778}
30879
30980uint32_t common_hal_busio_spi_get_frequency (busio_spi_obj_t * self ) {
310- return 0 ;//samd_peripherals_spi_baud_reg_value_to_baudrate(hri_sercomspi_read_BAUD_reg(self->spi_desc.dev.prvt));
81+ return 0 ;
31182}
31283
31384uint8_t common_hal_busio_spi_get_phase (busio_spi_obj_t * self ) {
314- //void * hw = self->spi_desc.dev.prvt;
315- return 0 ;//hri_sercomspi_get_CTRLA_CPHA_bit(hw);
85+ return 0 ;
31686}
31787
31888uint8_t common_hal_busio_spi_get_polarity (busio_spi_obj_t * self ) {
319- //void * hw = self->spi_desc.dev.prvt;
320- return 0 ;//hri_sercomspi_get_CTRLA_CPOL_bit(hw);
321- }
89+ return 0 ;
0 commit comments