int hw_spi_transfer (size_t port, size_t buffer_length, const uint8_t *txbuf, uint8_t *rxbuf, uint32_t txref, uint32_t rxref, size_t chunk_size, uint32_t repeat, int8_t chip_select, uint32_t cs_delay_us, void (*callback)()) { // Make sure that cs pin is high to start if (chip_select != -1) { hw_digital_output(chip_select); hw_digital_write(chip_select, 1); } hw_spi_transfer_setup (port, buffer_length, txbuf, rxbuf, txref, rxref, chunk_size, repeat, chip_select, cs_delay_us, callback); if (repeat == 0 || chunk_size > buffer_length) { tm_event_trigger(&async_spi_event); } hw_spi_transfer_step(); return 0; }
void default_complete_cb() { // Pull cs pin high if a cs pin is set if (spi_async_status.chip_select != -1) { hw_digital_write(spi_async_status.chip_select, 1); } // Set offset to next command in the txbuf spi_async_status.chunk_offset += spi_async_status.chunk_size; if ((spi_async_status.chunk_offset + spi_async_status.chunk_size) > spi_async_status.buffer_length) { spi_async_status.chunk_offset = 0; if (--spi_async_status.repeat == 0) { tm_event_trigger(&async_spi_event); return; } } if (spi_async_status.chip_select != -1) { hw_wait_us(spi_async_status.cs_delay_us); } hw_spi_transfer_step(); }
void hw_timer_update_interrupt() { if (tm_timer_waiting()) { tm_event_trigger(&tm_timer_event); } }