ADC is working, touch sensors roughly calibrated
tested with true's thumb
This commit is contained in:
parent
7827085947
commit
d280037880
@ -17,7 +17,7 @@
|
||||
#define CHAN_IS_TOUCH 1
|
||||
#define CHAN_IS_LIGHTSENSE 2
|
||||
|
||||
#define TOUCH_DEFAULT_CHARGE 0x88
|
||||
#define TOUCH_DEFAULT_CHARGE 0x4c
|
||||
#define TOUCH_DEFAULT_THRESH 0x800
|
||||
|
||||
|
||||
@ -39,7 +39,8 @@ static AdcChan adc_chan[ADC_CHANNELS] = {0};
|
||||
|
||||
void adc_init()
|
||||
{
|
||||
ADC_InitTypeDef adc = {0};
|
||||
NVIC_InitTypeDef nvic;
|
||||
ADC_InitTypeDef adc = {0};
|
||||
|
||||
// configure pin struct
|
||||
for (uint8_t i = 0; i < ADC_CHANNELS; i++) {
|
||||
@ -49,12 +50,29 @@ void adc_init()
|
||||
}
|
||||
|
||||
adc_chan[0].chan = ADC_Channel_0;
|
||||
adc_chan[0].timing = 0x4f;
|
||||
adc_chan[0].thresh = 3380;
|
||||
|
||||
adc_chan[1].chan = ADC_Channel_1;
|
||||
adc_chan[1].thresh = 3580;
|
||||
|
||||
adc_chan[2].chan = ADC_Channel_2;
|
||||
adc_chan[2].thresh = 3380;
|
||||
|
||||
adc_chan[3].chan = ADC_Channel_3;
|
||||
adc_chan[3].timing = 0x54;
|
||||
adc_chan[3].thresh = 3450;
|
||||
|
||||
adc_chan[4].chan = ADC_Channel_4;
|
||||
adc_chan[4].timing = 0x44;
|
||||
adc_chan[4].thresh = 3000;
|
||||
|
||||
adc_chan[5].chan = ADC_Channel_8;
|
||||
adc_chan[5].thresh = 3380;
|
||||
|
||||
adc_chan[6].chan = ADC_Channel_13;
|
||||
adc_chan[6].timing = 0x4a;
|
||||
adc_chan[6].thresh = 3550;
|
||||
|
||||
adc_chan[7].chan = ADC_Channel_9;
|
||||
adc_chan[7].type = CHAN_IS_LIGHTSENSE;
|
||||
@ -75,6 +93,17 @@ void adc_init()
|
||||
ADC_Init(ADC1, &adc);
|
||||
|
||||
ADC_Cmd(ADC1, ENABLE);
|
||||
|
||||
// configure ADC interrupt
|
||||
nvic.NVIC_IRQChannel = ADC1_IRQn;
|
||||
nvic.NVIC_IRQChannelPreemptionPriority = 0;
|
||||
nvic.NVIC_IRQChannelSubPriority = 4;
|
||||
nvic.NVIC_IRQChannelCmd = ENABLE;
|
||||
|
||||
// enable interrupt
|
||||
ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
|
||||
ADC1->STATR = 0; // clear flags
|
||||
NVIC_Init(&nvic);
|
||||
}
|
||||
|
||||
int8_t adc_get_tkey(uint8_t key_idx)
|
||||
@ -92,21 +121,19 @@ int8_t adc_get_tkey(uint8_t key_idx)
|
||||
void adc_next()
|
||||
{
|
||||
AdcChan *chan;
|
||||
uint8_t timeout = 0;
|
||||
volatile uint8_t timeout = 0;
|
||||
|
||||
// todo:
|
||||
// lightsense is timing-sensitive. will need to have this as an overridden channel?
|
||||
|
||||
// get next index
|
||||
adc_idx++;
|
||||
if (adc_idx > (sizeof(adc_chan) / sizeof(adc_chan[0]))) {
|
||||
adc_idx = 0;
|
||||
}
|
||||
|
||||
// so long as the channel is enabled
|
||||
while (!(adc_chan[adc_idx].type & CHAN_ENABLED) && (timeout++ < ADC_CHANNELS)) {
|
||||
do {
|
||||
adc_idx++;
|
||||
}
|
||||
adc_idx %= (sizeof(adc_chan) / sizeof(adc_chan[0]));
|
||||
if (adc_chan[adc_idx].type & CHAN_ENABLED)
|
||||
break;
|
||||
} while (timeout++ < ADC_CHANNELS);
|
||||
|
||||
// if nothing is enabled, break out
|
||||
if (timeout == ADC_CHANNELS)
|
||||
@ -115,7 +142,7 @@ void adc_next()
|
||||
chan = &adc_chan[adc_idx];
|
||||
|
||||
// configure sampling
|
||||
switch (chan->type) {
|
||||
switch (chan->type & ~CHAN_ENABLED) {
|
||||
case CHAN_IS_NORMAL: {
|
||||
TKey1->CTLR1 &= ~ADC_TKENABLE; // disable TouchKey
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user