Skip to content

Commit

Permalink
Merge pull request #241 from recallmenot/SPI_fix
Browse files Browse the repository at this point in the history
SPI lib: fixed bugs discovered by JKT
  • Loading branch information
cnlohr authored Sep 24, 2023
2 parents 42cb809 + a31b7c1 commit 1824f66
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions extralibs/ch32v003_SPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static inline void SPI_write_16(uint16_t data);
// send a command and get a response from the SPI device
// you'll use this for most devices
static inline uint8_t SPI_transfer_8(uint8_t data);
static inline uint8_t SPI_transfer_16(uint16_t data);
static inline uint16_t SPI_transfer_16(uint16_t data);

// SPI peripheral power enable / disable (default off, init() automatically enables)
// send SPI peripheral to sleep
Expand Down Expand Up @@ -238,15 +238,15 @@ static inline void SPI_init() {
}

static inline void SPI_begin_8() {
SPI1->CTLR1 |= SPI_DataSize_8b; // DFF 16bit data-length enable, writable only when SPE is 0
SPI1->CTLR1 |= CTLR1_SPE_Set;
SPI1->CTLR1 &= ~(SPI_CTLR1_DFF); // DFF 16bit data-length enable, writable only when SPE is 0
SPI1->CTLR1 |= SPI_CTLR1_SPE;
}
static inline void SPI_begin_16() {
SPI1->CTLR1 |= SPI_DataSize_16b; // DFF 16bit data-length enable, writable only when SPE is 0
SPI1->CTLR1 |= CTLR1_SPE_Set;
SPI1->CTLR1 |= SPI_CTLR1_DFF; // DFF 16bit data-length enable, writable only when SPE is 0
SPI1->CTLR1 |= SPI_CTLR1_SPE;
}
static inline void SPI_end() {
SPI1->CTLR1 &= CTLR1_SPE_Reset;
SPI1->CTLR1 &= ~(SPI_CTLR1_SPE);
}

#if defined(CH32V003_SPI_NSS_SOFTWARE_PC3)
Expand Down Expand Up @@ -290,7 +290,7 @@ static inline uint8_t SPI_transfer_8(uint8_t data) {
#endif
return SPI_read_8();
}
static inline uint8_t SPI_transfer_16(uint16_t data) {
static inline uint16_t SPI_transfer_16(uint16_t data) {
#if defined(CH32V003_SPI_NSS_SOFTWARE_PC3) || defined(CH32V003_SPI_NSS_SOFTWARE_PC4)
SPI_NSS_software_high();
#endif
Expand Down

0 comments on commit 1824f66

Please sign in to comment.