YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
adc14_msp432.h
1/*
2 * adc14_msp432.h
3 *
4 * Created on: 10.04.2016
5 * Author: Andreas Terstegge
6 */
7
8#ifndef _ADC14_MSP432_H_
9#define _ADC14_MSP432_H_
10
11#include "adc_interface.h"
12
13extern "C" {
14void ADC14_IRQHandler(void);
15}
16
17namespace ADC {
18 // ADC14 window irq modes
19 const uint16_t BELOW_LOW = 0x0001;
20 const uint16_t ABOVE_HIGH = 0x0002;
21 const uint16_t WITHIN_WIN = 0x0004;
22}
23
25 public:
26 static adc14_msp432 inst;
27
28 // Basic ADC functions
29 void adcMode (uint8_t channel, uint16_t mode) override;
30 adc_mode_t getMode (uint8_t channel) override;
31 uint16_t adcReadRaw (uint8_t channel) override;
32 float adcReadVoltage(uint8_t channel) override;
33 float rawToVoltage (uint8_t channel, uint16_t raw) override;
34
35 // Additional ADC methods for ADC14
36 void adcSetupScan (uint16_t res);
37 void attachScanIrq(uint8_t channel,
38 void (*handler)(uint16_t chan, uint16_t value) );
39 void adcStartScan (uint8_t start_channel, uint8_t end_channel);
40 void adcStopScan ();
41 uint16_t adcReadScan(uint8_t channel);
42
43 // The following method must only be used with ONE channel!
44 // After calling the handler, the irq is disabled!
45 void attachWinIrq (uint8_t channel,
46 void (*handler)(uint16_t val, uint16_t irq_mode),
47 uint16_t low, uint16_t high,
48 uint16_t irq_mode);
49
50 // IRQ handlers are our best friends
51 friend void ADC14_IRQHandler(void);
52
53 private:
54
56
57 void set_resolution (uint16_t res);
58
59 void handleIrq(uint32_t iv);
60
61 void (* _irqHandlers[24])(uint16_t, uint16_t);
62 void (* _irqWinHandler) (uint16_t, uint16_t);
63 uint16_t _irqWinMode;
64 uint8_t _irqWinChannel;
65
66 uint16_t _modes[24];
67 uint16_t _current_mode;
68};
69
70
71// This small wrapper class provides ADC
72// functionality for a single channel.
73
75 public:
77 : adc_channel(adc14_msp432::inst) { }
78
79 adc14_msp432_channel(uint16_t c)
80 : adc_channel(adc14_msp432::inst, c) { }
81
82 void attachScanIrq(void (*handler)(uint16_t chan, uint16_t value)) {
83 adc14_msp432::inst.attachScanIrq(_channel, handler);
84 }
85 uint16_t adcReadScan() {
86 return adc14_msp432::inst.adcReadScan(_channel);
87 }
88 void attachWinIrq(void (*handler)(uint16_t val, uint16_t irq_mode),
89 uint16_t low, uint16_t high,
90 uint16_t irq_mode) {
91 adc14_msp432::inst.attachWinIrq(_channel, handler, low, high, irq_mode);
92 }
93};
94
95#endif // _ADC14_MSP432_H_
96