Skip to content

Commit

Permalink
Add support for multi-device SPI bus.
Browse files Browse the repository at this point in the history
  • Loading branch information
jovanbulck committed Sep 7, 2017
1 parent e80ef7d commit e5e1a34
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build*/
*~
*.kdev*
*.swp
4 changes: 2 additions & 2 deletions include/sancus_support/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ typedef enum
} SpiCpha;

void spi_init(SpiCpol cpol, SpiCpha cpha, unsigned int clk_div);
void spi_select(void);
void spi_deselect(void);
void spi_select(int dev);
#define spi_deselect() spi_select(0x0)

uint8_t spi_write_read_byte(uint8_t data);
void spi_write_byte(uint8_t data);
Expand Down
21 changes: 9 additions & 12 deletions src/dev/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#define SPI_CNTRL *(volatile uint8_t*)0x0151
#define SPI_STATUS *(volatile uint8_t*)0x0152

#define SPI_CPOL 0
#define SPI_CPHA 1
#define SPI_SELECT 2
#define SPI_CLK_DIV 3
#define SPI_CPOL 0
#define SPI_CPHA 1
#define SPI_SELECT 2
#define SPI_CLK_DIV 4
#define SPI_SELECT_WIDTH (SPI_CLK_DIV - SPI_SELECT)

#define SPI_BUSY 0x01
#define SPI_BUSY 0x01

void spi_init(SpiCpol cpol, SpiCpha cpha, unsigned int clk_div)
{
Expand All @@ -18,14 +19,10 @@ void spi_init(SpiCpol cpol, SpiCpha cpha, unsigned int clk_div)
(clk_div << SPI_CLK_DIV);
}

void spi_select()
void spi_select(int dev)
{
SPI_CNTRL |= (1 << SPI_SELECT);
}

void spi_deselect()
{
SPI_CNTRL &= ~(1 << SPI_SELECT);
dev &= ((1 << SPI_SELECT_WIDTH) - 1);
SPI_CNTRL |= (dev << SPI_SELECT);
}

uint8_t spi_write_read_byte(uint8_t data)
Expand Down

0 comments on commit e5e1a34

Please sign in to comment.