2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
54 # define AO_ADC_LAST 7
57 # define AO_ADC_LAST 6
60 # define AO_ADC_LAST 5
63 # define AO_ADC_LAST 4
66 # define AO_ADC_LAST 3
69 # define AO_ADC_LAST 2
72 # define AO_ADC_LAST 1
75 # define AO_ADC_LAST 0
85 static uint8_t ao_adc_ready;
87 void lpc_adc_isr(void)
89 uint32_t stat = lpc_adc.stat;
90 uint16_t *out = (uint16_t *) &ao_data_ring[ao_data_head].adc;
91 vuint32_t *in = &lpc_adc.dr[0];
96 /* Store converted values in packet */
99 *out++ = lpc_adc.dr[0] >> 1;
102 *out++ = lpc_adc.dr[1] >> 1;
105 *out++ = lpc_adc.dr[2] >> 1;
108 *out++ = lpc_adc.dr[3] >> 1;
111 *out++ = lpc_adc.dr[4] >> 1;
114 *out++ = lpc_adc.dr[5] >> 1;
117 *out++ = lpc_adc.dr[6] >> 1;
120 *out++ = lpc_adc.dr[7] >> 1;
123 AO_DATA_PRESENT(AO_DATA_ADC);
124 if (ao_data_present == AO_DATA_ALL) {
126 ao_data_ring[ao_data_head].ms5607_raw = ao_ms5607_current;
129 ao_data_ring[ao_data_head].mma655x = ao_mma655x_current;
132 ao_data_ring[ao_data_head].hmc5883 = ao_hmc5883_current;
135 ao_data_ring[ao_data_head].mpu6000 = ao_mpu6000_current;
137 ao_data_ring[ao_data_head].tick = ao_tick_count;
138 ao_data_head = ao_data_ring_next(ao_data_head);
139 ao_wakeup((void *) &ao_data_head);
144 #define AO_ADC_MASK ((AO_ADC_0 << 0) | \
153 #define AO_ADC_CLKDIV (AO_LPC_CLKOUT / 4500000)
156 * Start the ADC sequence using the DMA engine
165 lpc_adc.cr = ((AO_ADC_MASK << LPC_ADC_CR_SEL) |
166 (AO_ADC_CLKDIV << LPC_ADC_CR_CLKDIV) |
167 (1 << LPC_ADC_CR_BURST) |
168 (LPC_ADC_CR_CLKS_11 << LPC_ADC_CR_CLKS));
172 ao_adc_dump(void) __reentrant
174 struct ao_data packet;
178 ao_data_get(&packet);
180 AO_ADC_DUMP(&packet);
182 printf("tick: %5u", packet.tick);
183 d = (int16_t *) (&packet.adc);
184 for (i = 0; i < AO_NUM_ADC; i++)
185 printf (" %2d: %5d", i, d[i]);
190 __code struct ao_cmds ao_adc_cmds[] = {
191 { ao_adc_dump, "a\0Display current ADC values" },
198 lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_ADC);
199 lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_ADC_PD);
201 /* Enable interrupt when last channel is complete */
202 lpc_adc.inten = (1 << AO_ADC_LAST);
204 lpc_nvic_set_enable(LPC_ISR_ADC_POS);
205 lpc_nvic_set_priority(LPC_ISR_ADC_POS, AO_LPC_NVIC_CLOCK_PRIORITY);
207 ao_enable_analog(0, 11);
210 ao_enable_analog(0, 12);
213 ao_enable_analog(0, 13);
216 ao_enable_analog(0, 14);
219 ao_enable_analog(0, 14);
222 ao_enable_analog(0, 14);
225 ao_enable_analog(0, 14);
228 ao_enable_analog(0, 14);
230 ao_cmd_register(&ao_adc_cmds[0]);