Fixed error of writing to SPI registers with memcpy (#352)

fixed memcpy() writing registers bug
This commit is contained in:
Ruslan V. Uss 2017-03-15 18:18:32 +05:00 committed by GitHub
parent 20674f8470
commit 1457a3ed19

View file

@ -189,7 +189,9 @@ static void _spi_buf_transfer(uint8_t bus, const void *out_data, void *in_data,
_wait(bus);
size_t bytes = len * (uint8_t)word_size;
_set_size(bus, bytes);
memcpy((void *)SPI(bus).W, out_data, bytes);
// memcpy((void *)SPI(bus).W, out_data, bytes); // <- It's buggy
for (uint8_t i = 0; i < bytes; i ++)
((uint8_t *)SPI(bus).W)[i] = ((uint8_t *)out_data)[i];
_spi_buf_prepare(bus, len, e, word_size);
_start(bus);
_wait(bus);
@ -221,8 +223,8 @@ uint32_t spi_transfer_32(uint8_t bus, uint32_t data)
return res;
}
static void _rearm_extras_bit(uint8_t bus, bool arm) {
static void _rearm_extras_bit(uint8_t bus, bool arm)
{
if (!_minimal_pins[bus]) return;
static uint8_t status[2];
@ -230,14 +232,27 @@ static void _rearm_extras_bit(uint8_t bus, bool arm) {
{
if (status[bus] & 0x01) SPI(bus).USER0 |= (SPI_USER0_ADDR);
if (status[bus] & 0x02) SPI(bus).USER0 |= (SPI_USER0_COMMAND);
if (status[bus] & 0x04) SPI(bus).USER0 |= (SPI_USER0_DUMMY | SPI_USER0_MISO);
if (status[bus] & 0x04)
SPI(bus).USER0 |= (SPI_USER0_DUMMY | SPI_USER0_MISO);
status[bus] = 0;
}
else
{
if (SPI(bus).USER0 & SPI_USER0_ADDR) { SPI(bus).USER0 &= ~(SPI_USER0_ADDR) ; status[bus] |= 0x01 ; }
if (SPI(bus).USER0 & SPI_USER0_COMMAND) { SPI(bus).USER0 &= ~(SPI_USER0_COMMAND) ; status[bus] |= 0x02 ; }
if (SPI(bus).USER0 & SPI_USER0_DUMMY) { SPI(bus).USER0 &= ~(SPI_USER0_DUMMY | SPI_USER0_MISO); status[bus] |= 0x04 ; }
if (SPI(bus).USER0 & SPI_USER0_ADDR)
{
SPI(bus).USER0 &= ~(SPI_USER0_ADDR);
status[bus] |= 0x01;
}
if (SPI(bus).USER0 & SPI_USER0_COMMAND)
{
SPI(bus).USER0 &= ~(SPI_USER0_COMMAND);
status[bus] |= 0x02;
}
if (SPI(bus).USER0 & SPI_USER0_DUMMY)
{
SPI(bus).USER0 &= ~(SPI_USER0_DUMMY | SPI_USER0_MISO);
status[bus] |= 0x04;
}
}
}
@ -268,7 +283,8 @@ size_t spi_transfer(uint8_t bus, const void *out_data, void *in_data, size_t len
return len;
}
static void _repeat_send(uint8_t bus, uint32_t* dword,int32_t* repeats,spi_word_size_t size)
static void _repeat_send(uint8_t bus, uint32_t *dword, int32_t *repeats,
spi_word_size_t size)
{
uint8_t i = 0;
while (*repeats > 0)