SPISlave works.

pull/159/head
tkuyucu 2013-12-06 10:01:28 +01:00
parent 4ba79b77b4
commit 105c31bcb3
5 changed files with 27 additions and 37 deletions

View File

@ -36,27 +36,20 @@ typedef enum {
#define STDIO_UART_TX TX_PIN_NUMBER
#define STDIO_UART_RX RX_PIN_NUMBER
#define STDIO_UART UART_0
typedef enum {
PWM_1 = 0,
PWM_2,
PWM_3,
PWM_4
} PWMName;
/*
typedef enum {
I2C_0 = (int)I2C0_BASE,
I2C_1 = (int)I2C1_BASE,
} I2CName;
#define TPM_SHIFT 8
typedef enum {
PWM_1 = (0 << TPM_SHIFT) | (0), // TPM0 CH0
PWM_2 = (0 << TPM_SHIFT) | (1), // TPM0 CH1
PWM_3 = (0 << TPM_SHIFT) | (2), // TPM0 CH2
PWM_4 = (0 << TPM_SHIFT) | (3), // TPM0 CH3
PWM_5 = (0 << TPM_SHIFT) | (4), // TPM0 CH4
PWM_6 = (0 << TPM_SHIFT) | (5), // TPM0 CH5
PWM_7 = (1 << TPM_SHIFT) | (0), // TPM1 CH0
PWM_8 = (1 << TPM_SHIFT) | (1), // TPM1 CH1
PWM_9 = (2 << TPM_SHIFT) | (0), // TPM2 CH0
PWM_10 = (2 << TPM_SHIFT) | (1) // TPM2 CH1
} PWMName;
#define CHANNELS_A_SHIFT 5
typedef enum {

View File

@ -61,7 +61,7 @@ typedef enum {
p28=28,
p29=29,
p30=30,
p31=31,
// p31=31,
LED_START = p18,
LED_STOP = p19,
@ -83,10 +83,10 @@ typedef enum {
USBTX = TX_PIN_NUMBER,
USBRX = RX_PIN_NUMBER,
SPI_PSELSCK0 = p31,
SPI_PSELSCK0 = p25,
SPI_PSELMOSI0 = p20,
SPI_PSELMISO0 = p22,
SPI_PSELSS0 = p30,
SPI_PSELSS0 = p24,
SPI_PSELSCK1 = p29,
SPI_PSELMOSI1 = p21,

View File

@ -39,7 +39,7 @@
#define DEVICE_ETHERNET 0
#define DEVICE_PWMOUT 0
#define DEVICE_PWMOUT 1
#define DEVICE_SEMIHOST 0
#define DEVICE_LOCALFILESYSTEM 0

View File

@ -43,6 +43,10 @@ struct port_s {
uint32_t mask;
};
struct pwmout_s {
PWMName pwm;
PinName pin;
};
/*
struct gpio_irq_s {

View File

@ -45,12 +45,10 @@ static const PinMap PinMap_SPI_SSEL[] = {
{NC , NC , 0}
};
// {SPI_PSELSS0 , SPI_0, 0x01},
#define SPIS_MESSAGE_SIZE 4
volatile uint8_t m_tx_buf[SPIS_MESSAGE_SIZE] = {0,0,0,0};
volatile uint8_t m_rx_buf[SPIS_MESSAGE_SIZE] = {5,5,5,5};
#define SPIS_MESSAGE_SIZE 1
volatile uint8_t m_tx_buf[SPIS_MESSAGE_SIZE] = {0};//{0,0,0,0};
volatile uint8_t m_rx_buf[SPIS_MESSAGE_SIZE] = {0};//{0,0,0,0};
static inline int ssp_disable(spi_t *obj);
static inline int ssp_enable(spi_t *obj);
void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel) {
// determine the SPI to use
@ -203,11 +201,6 @@ static inline int spi_writeable(spi_t *obj) {
}
/*static inline void spi_write(spi_t *obj, int value) {
obj->spi->DR = value;
}*/
static inline int spi_read(spi_t *obj) {
while (!spi_readable(obj)); //timeout ?
obj->spi->EVENTS_READY =0;
@ -220,12 +213,8 @@ int spi_master_write(spi_t *obj, int value) {
return spi_read(obj);
}
static inline int spis_readable(spi_t *obj) {
}
static inline int spis_writeable(spi_t *obj) {
return (obj->spis->EVENTS_ACQUIRED==1);
}
int spi_slave_receive(spi_t *obj) {
@ -238,7 +227,11 @@ int spi_slave_receive(spi_t *obj) {
int spi_slave_read(spi_t *obj) {
//&m_rx_buf[0] = obj->spis->RXDPTR;
int val = m_rx_buf[3]<<24 | m_rx_buf[2] <<16 | m_rx_buf[1] <<8 | m_rx_buf[0];
int val =m_rx_buf[0];// m_rx_buf[3]<<24 | m_rx_buf[2] <<16 | m_rx_buf[1] <<8 | m_rx_buf[0];
//m_rx_buf[0] =0;
//m_rx_buf[1] =0;
//m_rx_buf[2] =0;
//m_rx_buf[3] =0;
return val;//m_rx_buf[3];//obj->spis->RXDPTR;//
}
@ -247,9 +240,9 @@ void spi_slave_write(spi_t *obj, int value) {
while (!spis_writeable(obj)) ;
//obj->spis->TXDPTR = value;
m_tx_buf[0]= value & 0xFF;
m_tx_buf[1]= value & 0xFF00;
m_tx_buf[2]= value & 0xFF0000;
m_tx_buf[3]= value & 0xFF000000;
//m_tx_buf[1]= value & 0xFF00;
//m_tx_buf[2]= value & 0xFF0000;
//m_tx_buf[3]= value & 0xFF000000;
obj->spis->TXDPTR = (uint32_t)m_tx_buf;
//obj->spis->RXDPTR = (uint32_t)m_rx_buf;
obj->spis->TASKS_RELEASE=1;