Skip to content
Permalink
Browse files

rename SPI chip select defines to match older convention

  • Loading branch information
catfact committed Mar 24, 2016
1 parent ebb7a9b commit 97a9fbce7261539a8eaddf821de2d7bbfcca1f90
Showing with 47 additions and 34 deletions.
  1. +8 −3 conf/teletype/conf_board.h
  2. +5 −3 conf/trilogy/conf_board.h
  3. +20 −14 src/adc.c
  4. +3 −3 src/init_teletype.c
  5. +2 −2 src/init_trilogy.c
  6. +9 −9 src/screen.c
@@ -149,9 +149,14 @@
#define SPI_NPCS2_PIN AVR32_SPI_NPCS_2_1_PIN
#define SPI_NPCS2_FUNCTION AVR32_SPI_NPCS_2_1_FUNCTION

#define DAC_SPI 0
#define ADC_SPI 1
#define OLED_SPI 2
// peripheral addresses
#define ADC_SPI SPI
#define DAC_SPI SPI

// chip select indices
#define DAC_SPI_NPCS 0
#define ADC_SPI_NPCS 1
#define OLED_SPI_NPCS 2


//TWI
@@ -126,7 +126,6 @@
#define SPARE_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
#define SPARE_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION


// SCK A15
// MISO A28
// MOSI A29
@@ -144,8 +143,11 @@
#define SPI_NPCS1_PIN AVR32_SPI_NPCS_1_0_PIN
#define SPI_NPCS1_FUNCTION AVR32_SPI_NPCS_1_0_FUNCTION

#define DAC_SPI 0
#define ADC_SPI 1
#define DAC_SPI_NPCS 0
#define ADC_SPI_NPCS 1

// compatibility with aleph
#define ADC_SPI SPI

//TWI
#define TWI (&AVR32_TWI)
@@ -25,10 +25,16 @@
#ifdef MOD_TRILOGY
#define AD7923_CMD_BASE ( AD7923_CTL_WRITE | AD7923_CTL_PM0 | AD7923_CTL_PM1 | AD7923_CTL_CODING)
#endif

#ifdef MOD_TELETYPE
#define AD7923_CMD_BASE ( AD7923_CTL_WRITE | AD7923_CTL_PM0 | AD7923_CTL_PM1 | AD7923_CTL_CODING | AD7923_CTL_RANGE)
#endif

#ifdef MOD_ALEPH
#define AD7923_CMD_BASE \
(AD7923_CTL_WRITE | AD7923_CTL_PM0 | AD7923_CTL_PM1 | AD7923_CTL_CODING)
#endif


// // adc events
// static const etype adctypes[4] = {
@@ -45,40 +51,40 @@ void adc_convert(U16 (*dst)[4]) {
// data into AD7923 is a left-justified 12-bit value in a 16-bit word
// so, always lshift the command before sending
cmd = ( AD7923_CMD_BASE ) << 4;
spi_selectChip(SPI, ADC_SPI);
spi_selectChip(SPI, ADC_SPI_NPCS);
spi_write(SPI, cmd);
spi_unselectChip(SPI, ADC_SPI);
spi_unselectChip(SPI, ADC_SPI_NPCS);

// get channel 0, setup channel 1
cmd = ( AD7923_CMD_BASE | AD7923_CTL_ADD0 ) << 4;
spi_selectChip(SPI, ADC_SPI);
spi_selectChip(SPI, ADC_SPI_NPCS);
spi_write(SPI, cmd);
spi_read(SPI, &val);
spi_unselectChip(SPI, ADC_SPI);
spi_unselectChip(SPI, ADC_SPI_NPCS);
(*dst)[0] = val & 0xfff;

// get channel 1, setup channel 2
cmd = ( AD7923_CMD_BASE | AD7923_CTL_ADD1 ) << 4;
spi_selectChip(SPI, ADC_SPI);
spi_selectChip(SPI, ADC_SPI_NPCS);
spi_write(SPI, cmd);
spi_read(SPI, &val);
spi_unselectChip(SPI, ADC_SPI);
spi_unselectChip(SPI, ADC_SPI_NPCS);
(*dst)[1] = val & 0xfff;

// get channel 2, setup channel 3
cmd = ( AD7923_CMD_BASE | AD7923_CTL_ADD1 | AD7923_CTL_ADD0 ) << 4;
spi_selectChip(SPI, ADC_SPI);
spi_selectChip(SPI, ADC_SPI_NPCS);
spi_write(SPI, cmd);
spi_read(SPI, &val);
spi_unselectChip(SPI, ADC_SPI);
spi_unselectChip(SPI, ADC_SPI_NPCS);
(*dst)[2] = val & 0xfff;

// get channel 3, dummy write
cmd = ( AD7923_CMD_BASE ) << 4;
spi_selectChip(SPI, ADC_SPI);
spi_selectChip(SPI, ADC_SPI_NPCS);
spi_write(SPI, cmd);
spi_read(SPI, &val);
spi_unselectChip(SPI, ADC_SPI);
spi_unselectChip(SPI, ADC_SPI_NPCS);
(*dst)[3] = val & 0xfff;

}
@@ -88,18 +94,18 @@ void init_adc(void) {
u16 cmd;

// at powerup, the part wants a dummy conversion with DIN high
spi_selectChip(SPI, ADC_SPI);
spi_selectChip(SPI, ADC_SPI_NPCS);
spi_write(SPI, 0xffff);
spi_unselectChip(SPI, ADC_SPI);
spi_unselectChip(SPI, ADC_SPI_NPCS);

// wait for powerup time (5us in datasheet)
delay_us(5);

// write base configuration
cmd = AD7923_CMD_BASE << 4;
spi_selectChip(SPI, ADC_SPI );
spi_selectChip(SPI, ADC_SPI_NPCS );
spi_write(SPI, cmd );
spi_unselectChip(SPI, ADC_SPI );
spi_unselectChip(SPI, ADC_SPI_NPCS );

}

@@ -182,7 +182,7 @@ extern void init_spi (void) {


spi_options_t spiOptions = {
.reg = DAC_SPI,
.reg = DAC_SPI_NPCS,
.baudrate = 2000000,
.bits = 8,
.trans_delay = 0,
@@ -204,7 +204,7 @@ extern void init_spi (void) {


// add ADC chip register
spiOptions.reg = ADC_SPI;
spiOptions.reg = ADC_SPI_NPCS;
spiOptions.baudrate = 20000000;
spiOptions.bits = 16;
spiOptions.spi_mode = 2;
@@ -217,7 +217,7 @@ extern void init_spi (void) {


// add OLED chip register
spiOptions.reg = OLED_SPI;
spiOptions.reg = OLED_SPI_NPCS;
spiOptions.baudrate = 40000000;
spiOptions.bits = 8;
spiOptions.spi_mode = 3;
@@ -185,7 +185,7 @@ extern void init_spi (void) {


spi_options_t spiOptions = {
.reg = DAC_SPI,
.reg = DAC_SPI_NPCS,
.baudrate = 2000000,
.bits = 8,
.trans_delay = 0,
@@ -208,7 +208,7 @@ extern void init_spi (void) {


// add ADC chip register
spiOptions.reg = ADC_SPI;
spiOptions.reg = ADC_SPI_NPCS;
spiOptions.baudrate = 20000000;
spiOptions.bits = 16;
spiOptions.spi_mode = 2;
@@ -34,11 +34,11 @@ static u32 nb; // count of destination bytes

static void write_command(U8 c);
static void write_command(U8 c) {
spi_selectChip(SPI, OLED_SPI);
spi_selectChip(SPI, OLED_SPI_NPCS);
// pull register select low to write a command
gpio_clr_gpio_pin(OLED_DC_PIN);
spi_write(SPI, c);
spi_unselectChip(SPI, OLED_SPI);
spi_unselectChip(SPI, OLED_SPI_NPCS);
}

// set the current drawing area of the physical screen (hopefully)
@@ -166,14 +166,14 @@ void init_oled(void) {
// set drawing region
screen_set_rect(x, y, w, h);
// select chip for data
spi_selectChip(SPI, OLED_SPI);
spi_selectChip(SPI, OLED_SPI_NPCS);
// register select high for data
gpio_set_gpio_pin(OLED_DC_PIN);
// send data
for(i=0; i<(nb); i++) {
spi_write(SPI, screenBuf[i]);
}
spi_unselectChip(SPI, OLED_SPI);
spi_unselectChip(SPI, OLED_SPI_NPCS);
}

// draw data at given rectangle, with starting byte offset within the region data.
@@ -219,25 +219,25 @@ void screen_draw_region_offset(u8 x, u8 y, u8 w, u8 h, u32 len, u8* data, u32 of
// set drawing region
screen_set_rect(x, y, w, h);
// select chip for data
spi_selectChip(SPI, OLED_SPI);
spi_selectChip(SPI, OLED_SPI_NPCS);
// register select high for data
gpio_set_gpio_pin(OLED_DC_PIN);
// send data
for(i=0; i<(nb); i++) {
spi_write(SPI, screenBuf[i]);
}
spi_unselectChip(SPI, OLED_SPI);
spi_unselectChip(SPI, OLED_SPI_NPCS);
}


// clear OLED RAM and local screenbuffer
void screen_clear(void) {
spi_selectChip(SPI, OLED_SPI);
spi_selectChip(SPI, OLED_SPI_NPCS);
// pull register select high to write data
gpio_set_gpio_pin(OLED_DC_PIN);
for(i=0; i<GRAM_BYTES; i++) {
screenBuf[i] = 0;
spi_write(SPI, 0);
}
spi_unselectChip(SPI, OLED_SPI);
}
spi_unselectChip(SPI, OLED_SPI_NPCS);
}

0 comments on commit 97a9fbc

Please sign in to comment.