Got MCP2521 to work
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
#include "mcp2521_hardware_handle.hpp"
|
||||
|
||||
|
||||
const uint8_t null_buffer[32] = {0};
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "mcp2521_hardware_esp.hpp"
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::spi_transmit(spi_transaction_t *t) {
|
||||
xSemaphoreTake(spiMutex, portMAX_DELAY);
|
||||
spi_device_transmit(this->spi_device_handle, t);
|
||||
xSemaphoreGive(spiMutex);
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd) {
|
||||
spi_transaction_ext_t t = {
|
||||
.base = {
|
||||
@@ -19,7 +28,7 @@ void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd) {
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
|
||||
@@ -38,7 +47,7 @@ void MCP2521_Hardware_Handle_ESP::execute(uint8_t cmd, uint8_t address) {
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length, uint8_t address) {
|
||||
@@ -49,15 +58,15 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
|
||||
.addr = address,
|
||||
.length = 8*length,
|
||||
.rxlength = 8*length,
|
||||
.tx_buffer = NULL,
|
||||
.tx_buffer = null_buffer,
|
||||
.rx_buffer = data
|
||||
},
|
||||
.command_bits = 8,
|
||||
.address_bits = 0,
|
||||
.address_bits = 8,
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length) {
|
||||
@@ -76,7 +85,7 @@ void MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t *data, size_t length
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||
@@ -88,7 +97,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||
.addr = address,
|
||||
.length = 8,
|
||||
.rxlength = 8,
|
||||
.tx_buffer = NULL,
|
||||
.tx_buffer = null_buffer,
|
||||
.rx_buffer = &result
|
||||
},
|
||||
.command_bits = 8,
|
||||
@@ -96,7 +105,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd, uint8_t address) {
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -109,7 +118,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
|
||||
.addr = 0,
|
||||
.length = 8,
|
||||
.rxlength = 8,
|
||||
.tx_buffer = NULL,
|
||||
.tx_buffer = null_buffer,
|
||||
.rx_buffer = &result
|
||||
},
|
||||
.command_bits = 8,
|
||||
@@ -117,7 +126,7 @@ uint8_t MCP2521_Hardware_Handle_ESP::read(uint8_t cmd) {
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -138,7 +147,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t lengt
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t length) {
|
||||
@@ -157,7 +166,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t *data, size_t lengt
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t address) {
|
||||
@@ -176,7 +185,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data, uint8_t addre
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data) {
|
||||
@@ -195,7 +204,7 @@ void MCP2521_Hardware_Handle_ESP::write(uint8_t cmd, uint8_t data) {
|
||||
.dummy_bits = 0,
|
||||
};
|
||||
|
||||
spi_device_transmit(this->spi_device_handle, (spi_transaction_t*)(&t));
|
||||
spi_transmit((spi_transaction_t*)(&t));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user