aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/ChangeLog/20200829/PR9023.md5
-rw-r--r--docs/adc_driver.md39
-rw-r--r--keyboards/handwired/promethium/config.h1
-rw-r--r--keyboards/handwired/promethium/promethium.c3
-rw-r--r--tmk_core/protocol/lufa/adafruit_ble.cpp4
5 files changed, 27 insertions, 25 deletions
diff --git a/docs/ChangeLog/20200829/PR9023.md b/docs/ChangeLog/20200829/PR9023.md
new file mode 100644
index 000000000..79ca2cb2f
--- /dev/null
+++ b/docs/ChangeLog/20200829/PR9023.md
@@ -0,0 +1,5 @@
1# Deprecation of `analogRead()`
2
3[#9023](https://github.com/qmk/qmk_firmware/pull/9023)
4
5This function takes Arduino pin numbers (eg. `9` vs. `B5`), which is at odds with the rest of the codebase. The replacement for this function is `analogReadPin()`.
diff --git a/docs/adc_driver.md b/docs/adc_driver.md
index f8fb94094..6e3d51386 100644
--- a/docs/adc_driver.md
+++ b/docs/adc_driver.md
@@ -45,9 +45,9 @@ Then place this include at the top of your code:
45 45
46Note that some of these pins are doubled-up on ADCs with the same channel. This is because the pins can be used for either ADC. 46Note that some of these pins are doubled-up on ADCs with the same channel. This is because the pins can be used for either ADC.
47 47
48Also note that the F0 and F3 use different numbering schemes. The F0 has a single ADC and the channels are 0-based, whereas the F3 has 4 ADCs and the channels are 1 based. This is because the F0 uses the `ADCv1` implementation of the ADC, whereas the F3 uses the `ADCv3` implementation. 48Also note that the F0 and F3 use different numbering schemes. The F0 has a single ADC and the channels are 0-indexed, whereas the F3 has 4 ADCs and the channels are 1-indexed. This is because the F0 uses the `ADCv1` implementation of the ADC, whereas the F3 uses the `ADCv3` implementation.
49 49
50|ADC|Channel|STM32F0XX|STM32F3XX| 50|ADC|Channel|STM32F0xx|STM32F3xx|
51|---|-------|---------|---------| 51|---|-------|---------|---------|
52|1 |0 |`A0` | | 52|1 |0 |`A0` | |
53|1 |1 |`A1` |`A0` | 53|1 |1 |`A1` |`A0` |
@@ -122,32 +122,29 @@ Also note that the F0 and F3 use different numbering schemes. The F0 has a singl
122|Function |Description | 122|Function |Description |
123|----------------------------|-------------------------------------------------------------------------------------------------------------------| 123|----------------------------|-------------------------------------------------------------------------------------------------------------------|
124|`analogReference(mode)` |Sets the analog voltage reference source. Must be one of `ADC_REF_EXTERNAL`, `ADC_REF_POWER` or `ADC_REF_INTERNAL`.| 124|`analogReference(mode)` |Sets the analog voltage reference source. Must be one of `ADC_REF_EXTERNAL`, `ADC_REF_POWER` or `ADC_REF_INTERNAL`.|
125|`analogRead(pin)` |Reads the value from the specified Arduino pin, eg. `4` for ADC6 on the ATmega32U4. | 125|`analogReadPin(pin)` |Reads the value from the specified pin, eg. `F6` for ADC6 on the ATmega32U4. |
126|`analogReadPin(pin)` |Reads the value from the specified QMK pin, eg. `F6` for ADC6 on the ATmega32U4. | 126|`pinToMux(pin)` |Translates a given pin to a mux value. If an unsupported pin is given, returns the mux value for "0V (GND)". |
127|`pinToMux(pin)` |Translates a given QMK pin to a mux value. If an unsupported pin is given, returns the mux value for "0V (GND)". |
128|`adc_read(mux)` |Reads the value from the ADC according to the specified mux. See your MCU's datasheet for more information. | 127|`adc_read(mux)` |Reads the value from the ADC according to the specified mux. See your MCU's datasheet for more information. |
129 128
130### ARM 129### ARM
131 130
132Note that care was taken to match all of the functions used for AVR devices, however complications in the ARM platform prevent that from always being possible. For example, the `STM32` chips do not have assigned Arduino pins. We could use the default pin numbers, but those numbers change based on the package type of the device. For this reason, please specify your target pins with their identifiers (`A0`, `F3`, etc.). Also note that there are some variants of functions that accept the target ADC for the pin. Some pins can be used for multiple ADCs, and this specified can help you pick which ADC will be used to interact with that pin. 131|Function |Description |
133 132|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
134|Function |Description | 133|`analogReadPin(pin)` |Reads the value from the specified pin, eg. `A0` for channel 0 on the STM32F0 and ADC1 channel 1 on the STM32F3. Note that if a pin can be used for multiple ADCs, it will pick the lower numbered ADC for this function. eg. `C0` will be channel 6 of ADC 1 when it could be used for ADC 2 as well.|
135|----------------------------|--------------------------------------------------------------------------------------------------------------------| 134|`analogReadPinAdc(pin, adc)`|Reads the value from the specified pin and ADC, eg. `C0, 1` will read from channel 6, ADC 2 instead of ADC 1. Note that the ADCs are 0-indexed for this function. |
136|`analogReadPin(pin)` |Reads the value from the specified QMK pin, eg. `A0` for channel 0 on the STM32F0 and ADC1 channel 1 on the STM32F3. Note that if a pin can be used for multiple ADCs, it will pick the lower numbered ADC for this function. eg. `C0` will be channel 6 of ADC 1 when it could be used for ADC 2 as well.| 135|`pinToMux(pin)` |Translates a given pin to a channel and ADC combination. If an unsupported pin is given, returns the mux value for "0V (GND)". |
137|`analogReadPinAdc(pin, adc)`|Reads the value from the specified QMK pin and ADC, eg. `C0, 1` will read from channel 6, ADC 2 instead of ADC 1. Note that the ADCs are 0-indexed for this function.| 136|`adc_read(mux)` |Reads the value from the ADC according to the specified pin and ADC combination. See your MCU's datasheet for more information. |
138|`pinToMux(pin)` |Translates a given QMK pin to a channel and ADC combination. If an unsupported pin is given, returns the mux value for "0V (GND)".|
139|`adc_read(mux)` |Reads the value from the ADC according to the specified pin and adc combination. See your MCU's datasheet for more information.|
140 137
141## Configuration 138## Configuration
142 139
143## ARM 140## ARM
144 141
145The ARM implementation of the ADC has a few additional options that you can override in your own keyboards and keymaps to change how it operates. 142The ARM implementation of the ADC has a few additional options that you can override in your own keyboards and keymaps to change how it operates. Please consult the corresponding `hal_adc_lld.h` in ChibiOS for your specific microcontroller for further documentation on your available options.
146 143
147|`#define` |Type |Default |Description| 144|`#define` |Type |Default |Description |
148|-------------------|------|---------------------|-----------| 145|---------------------|------|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
149|ADC_CIRCULAR_BUFFER|`bool`|`false` |If `TRUE`, then the implementation will use a circular buffer.| 146|`ADC_CIRCULAR_BUFFER`|`bool`|`false` |If `true`, then the implementation will use a circular buffer. |
150|ADC_NUM_CHANNELS |`int` |`1` |Sets the number of channels that will be scanned as part of an ADC operation. The current implementation only supports `1`.| 147|`ADC_NUM_CHANNELS` |`int` |`1` |Sets the number of channels that will be scanned as part of an ADC operation. The current implementation only supports `1`. |
151|ADC_BUFFER_DEPTH |`int` |`2` |Sets the depth of each result. Since we are only getting a 12-bit result by default, we set this to `2` bytes so we can contain our one value. This could be set to 1 if you opt for a 8-bit or lower result.| 148|`ADC_BUFFER_DEPTH` |`int` |`2` |Sets the depth of each result. Since we are only getting a 12-bit result by default, we set this to 2 bytes so we can contain our one value. This could be set to 1 if you opt for an 8-bit or lower result.|
152|ADC_SAMPLING_RATE |`int` |`ADC_SMPR_SMP_1P5` |Sets the sampling rate of the ADC. By default, it is set to the fastest setting. Please consult the corresponding `hal_adc_lld.h` in ChibiOS for your specific microcontroller for further documentation on your available options.| 149|`ADC_SAMPLING_RATE` |`int` |`ADC_SMPR_SMP_1P5` |Sets the sampling rate of the ADC. By default, it is set to the fastest setting. |
153|ADC_RESOLUTION |`int` |`ADC_CFGR1_RES_12BIT`|The resolution of your result. We choose 12 bit by default, but you can opt for 12, 10, 8, or 6 bit. Please consult the corresponding `hal_adc_lld.h` in ChibiOS for your specific microcontroller for further documentation on your available options.| 150|`ADC_RESOLUTION` |`int` |`ADC_CFGR1_RES_12BIT`|The resolution of your result. We choose 12 bit by default, but you can opt for 12, 10, 8, or 6 bit. |
diff --git a/keyboards/handwired/promethium/config.h b/keyboards/handwired/promethium/config.h
index f9560206b..20c5e6a85 100644
--- a/keyboards/handwired/promethium/config.h
+++ b/keyboards/handwired/promethium/config.h
@@ -150,7 +150,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
150//#define NO_ACTION_FUNCTION 150//#define NO_ACTION_FUNCTION
151 151
152#define PS2_MOUSE_INIT_DELAY 2000 152#define PS2_MOUSE_INIT_DELAY 2000
153#define BATTERY_PIN 9
154#define BATTERY_POLL 30000 153#define BATTERY_POLL 30000
155#define MAX_VOLTAGE 4.2 154#define MAX_VOLTAGE 4.2
156#define MIN_VOLTAGE 3.2 155#define MIN_VOLTAGE 3.2
diff --git a/keyboards/handwired/promethium/promethium.c b/keyboards/handwired/promethium/promethium.c
index 3cc0f5a8c..96bcf3ce1 100644
--- a/keyboards/handwired/promethium/promethium.c
+++ b/keyboards/handwired/promethium/promethium.c
@@ -3,6 +3,7 @@
3#include "timer.h" 3#include "timer.h"
4#include "matrix.h" 4#include "matrix.h"
5#include "musical_notes.h" 5#include "musical_notes.h"
6#include "adafruit_ble.h"
6 7
7float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_A4, 0.0625); 8float fauxclicky_pressed_note[2] = MUSICAL_NOTE(_A4, 0.0625);
8float fauxclicky_released_note[2] = MUSICAL_NOTE(_A4, 0.0625); 9float fauxclicky_released_note[2] = MUSICAL_NOTE(_A4, 0.0625);
@@ -11,7 +12,7 @@ float fauxclicky_beep_note[2] = MUSICAL_NOTE(_C6, 0.25);
11// cubic fit {3.3, 0}, {3.5, 2.9}, {3.6, 5}, {3.7, 8.6}, {3.8, 36}, {3.9, 62}, {4.0, 73}, {4.05, 83}, {4.1, 89}, {4.15, 94}, {4.2, 100} 12// cubic fit {3.3, 0}, {3.5, 2.9}, {3.6, 5}, {3.7, 8.6}, {3.8, 36}, {3.9, 62}, {4.0, 73}, {4.05, 83}, {4.1, 89}, {4.15, 94}, {4.2, 100}
12 13
13uint8_t battery_level(void) { 14uint8_t battery_level(void) {
14 float voltage = analogRead(BATTERY_PIN) * 2 * 3.3 / 1024; 15 float voltage = adafruit_ble_read_battery_voltage() * 2 * 3.3 / 1024;
15 if (voltage < MIN_VOLTAGE) return 0; 16 if (voltage < MIN_VOLTAGE) return 0;
16 if (voltage > MAX_VOLTAGE) return 255; 17 if (voltage > MAX_VOLTAGE) return 255;
17 return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255; 18 return (voltage - MIN_VOLTAGE) / (MAX_VOLTAGE - MIN_VOLTAGE) * 255;
diff --git a/tmk_core/protocol/lufa/adafruit_ble.cpp b/tmk_core/protocol/lufa/adafruit_ble.cpp
index b07407f38..79b35fca3 100644
--- a/tmk_core/protocol/lufa/adafruit_ble.cpp
+++ b/tmk_core/protocol/lufa/adafruit_ble.cpp
@@ -38,7 +38,7 @@
38 38
39#ifdef SAMPLE_BATTERY 39#ifdef SAMPLE_BATTERY
40# ifndef BATTERY_LEVEL_PIN 40# ifndef BATTERY_LEVEL_PIN
41# define BATTERY_LEVEL_PIN 7 41# define BATTERY_LEVEL_PIN B5
42# endif 42# endif
43#endif 43#endif
44 44
@@ -556,7 +556,7 @@ void adafruit_ble_task(void) {
556 if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) { 556 if (timer_elapsed(state.last_battery_update) > BatteryUpdateInterval && resp_buf.empty()) {
557 state.last_battery_update = timer_read(); 557 state.last_battery_update = timer_read();
558 558
559 state.vbat = analogRead(BATTERY_LEVEL_PIN); 559 state.vbat = analogReadPin(BATTERY_LEVEL_PIN);
560 } 560 }
561#endif 561#endif
562} 562}