Skip to content

Commit

Permalink
SPI interface suggestion #42
Browse files Browse the repository at this point in the history
  • Loading branch information
Murilotrevisan committed Apr 18, 2022
1 parent 91a3049 commit 5b87d8d
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion platform/arch/platform_arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ EXPORT void delay_ms(uint32_t time) { delay(time); }
typedef struct {
uint8_t address;
} i2c_device_t;

//#include <Wire.h>

/**
* Inicializa a biblioteca wire e acessa o bus 12c como controlador
Expand Down Expand Up @@ -137,4 +137,57 @@ EXPORT void gpio_toggle(gpio_pin_t pin) {
pinMode(pin.pin, OUTPUT);
digitalWrite(pin.pin, !digitalRead(pin.pin));
}
//#endif

/**
* Essa macro só é definida se o SPI for ser utilizado
*
*
*
*
*
*
*
*/
//#if defined(HAL_SPI_MODULE_ENABLED)


typedef struct {
gpio_pin_t pin;
} spi_device_t;
//#include <SPI.h>

/**
* Inicializa a biblioteca SPI
* Configura os pinos de SCK, MOSI e SS como outputs
* Pulling SCK e MOSI como low e SS como high
*
*/
SPI.begin();
#if defined(WIRE_HAS_TIMEOUT)
Wire.setWireTimeout(TIMEOUT, true);
#endif

EXPORT error_t spi_transceive(spi_device_t device, buffer_view_t rx_buffer,
buffer_view_t tx_buffer) {

if (tx_buffer.size != rx_buffer.size) {
return 1;
}
rx_buffer.data = SPI.transfer(tx_buffer.data); //receive rx and transmit tx
error_t error = rx_buffer;
return error;
}

EXPORT error_t spi_receive(spi_device_t device, buffer_view_t buffer_view) {
buffer_view.data = SPI.transfer(0x00); //envia um 0 para receber os dados
error_t error = buffer_view;
return error;
}

EXPORT error_t spi_transmit(spi_device_t device, buffer_view_t buffer_view) {
error_t error = SPI.transfer(buffer_view.data);
return error;
}

//#endif

0 comments on commit 5b87d8d

Please sign in to comment.