Skip to content

Commit e9d1ac0

Browse files
committed
final hookup
1 parent c62fe10 commit e9d1ac0

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

lib/pbio/drv/adc/adc_ev3.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@
3030
#include "../drv/block_device/block_device_ev3.h"
3131
#include "../drv/gpio/gpio_ev3.h"
3232

33-
#include <pbdrv/../../drv/uart/uart_debug_first_port.h>
34-
35-
// PROCESS(pbdrv_adc_process, "ADC");
36-
3733
#define PBDRV_CONFIG_ADC_EV3_NUM_DELAY_SAMPLES (2)
3834

3935
/**
@@ -100,15 +96,22 @@ void pbdrv_adc_set_callback(pbdrv_adc_callback_t callback) {
10096
}
10197

10298
pbio_error_t pbdrv_adc_get_ch(uint8_t ch, uint16_t *value) {
103-
*value = 1234;
99+
if (ch >= PBDRV_CONFIG_ADC_EV3_ADC_NUM_CHANNELS) {
100+
return PBIO_ERROR_INVALID_ARG;
101+
}
102+
103+
// XXX atomicity???
104+
uint16_t a, b;
105+
do {
106+
// Values for the requested channel are received several samples later.
107+
a = channel_data[ch + PBDRV_CONFIG_ADC_EV3_NUM_DELAY_SAMPLES];
108+
b = channel_data[ch + PBDRV_CONFIG_ADC_EV3_NUM_DELAY_SAMPLES];
109+
} while (a != b);
110+
111+
// Mask the data to 10 bits
112+
// XXX what was the old (x - 4096 * ch) logic supposed to do???
113+
*value = (a >> 2) & 0x3ff;
104114
return PBIO_SUCCESS;
105-
// if (ch >= PBDRV_CONFIG_ADC_EV3_ADC_NUM_CHANNELS) {
106-
// return PBIO_ERROR_INVALID_ARG;
107-
// }
108-
// // Values for the requested channel are received several samples later.
109-
// // The data only appears 12-bit but the last 2 bits are always zero.
110-
// *value = (channel_data[ch + PBDRV_CONFIG_ADC_EV3_NUM_DELAY_SAMPLES] - 4096 * ch) >> 2;
111-
// return PBIO_SUCCESS;
112115
}
113116

114117
static pbio_os_process_t pbdrv_adc_ev3_process;

lib/pbio/drv/block_device/block_device_ev3.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,9 @@ void pbdrv_block_device_init(void) {
678678
SPIConfigClkFormat(SOC_SPI_0_REGS, SPI_CLK_POL_HIGH | SPI_CLK_INPHASE, SPI_DATA_FORMAT0);
679679
SPIShiftMsbFirst(SOC_SPI_0_REGS, SPI_DATA_FORMAT0);
680680
SPICharLengthSet(SOC_SPI_0_REGS, 8, SPI_DATA_FORMAT0);
681+
#if PBDRV_CONFIG_ADC_EV3
681682
pbdrv_adc_ev3_configure_data_format();
683+
#endif
682684

683685
// Configure the GPIO pins.
684686
pbdrv_gpio_alt(&pin_spi0_mosi, SYSCFG_PINMUX3_PINMUX3_15_12_SPI0_SIMO0);

0 commit comments

Comments
 (0)