| 1 |
/* |
| 2 |
* The MIT License (MIT) |
| 3 |
* |
| 4 |
* Copyright (c) 2021 Renesas Electronics Corporation |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and associated documentation files (the "Software"), to deal |
| 8 |
* in the Software without restriction, including without limitation the rights |
| 9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
* copies of the Software, and to permit persons to whom the Software is |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be included in |
| 14 |
* all copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
* THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#ifndef RA_ADC_H_ |
| 26 |
#define RA_ADC_H_ |
| 27 |
|
| 28 |
#include <stdint.h> |
| 29 |
#include <stdbool.h> |
| 30 |
|
| 31 |
#if defined(RA4M1) | defined(RA4W1) |
| 32 |
#define ADC_RESOLUTION (14) |
| 33 |
#else |
| 34 |
#define ADC_RESOLUTION (12) |
| 35 |
#endif |
| 36 |
|
| 37 |
enum ADC14_PIN |
| 38 |
{ |
| 39 |
#if defined(RA4M1) |
| 40 |
|
| 41 |
AN000 = 0, |
| 42 |
AN001 = 1, |
| 43 |
AN002 = 2, |
| 44 |
AN003 = 3, |
| 45 |
AN004 = 4, |
| 46 |
AN005 = 5, |
| 47 |
AN006 = 6, |
| 48 |
AN007 = 7, |
| 49 |
AN008 = 8, |
| 50 |
AN009 = 9, |
| 51 |
AN010 = 10, |
| 52 |
AN011 = 11, |
| 53 |
AN012 = 12, |
| 54 |
AN013 = 13, |
| 55 |
AN014 = 14, |
| 56 |
AN016 = 16, |
| 57 |
AN017 = 17, |
| 58 |
AN018 = 18, |
| 59 |
AN019 = 19, |
| 60 |
AN020 = 20, |
| 61 |
AN021 = 21, |
| 62 |
AN022 = 22, |
| 63 |
AN023 = 23, |
| 64 |
AN024 = 24, |
| 65 |
AN025 = 25, |
| 66 |
|
| 67 |
#elif defined(RA4W1) |
| 68 |
|
| 69 |
AN004 = 4, |
| 70 |
AN005 = 5, |
| 71 |
AN006 = 6, |
| 72 |
AN009 = 9, |
| 73 |
AN010 = 10, |
| 74 |
AN017 = 17, |
| 75 |
AN019 = 19, |
| 76 |
AN020 = 20, |
| 77 |
|
| 78 |
#elif defined(RA6M1) |
| 79 |
|
| 80 |
AN000 = 0, |
| 81 |
AN001 = 1, |
| 82 |
AN002 = 2, |
| 83 |
AN003 = 3, |
| 84 |
AN004 = 4, |
| 85 |
AN005 = 5, |
| 86 |
AN006 = 6, |
| 87 |
AN007 = 7, |
| 88 |
AN008 = 8, |
| 89 |
AN009 = 9, |
| 90 |
AN010 = 10, |
| 91 |
AN011 = 11, |
| 92 |
AN012 = 12, |
| 93 |
AN013 = 13, |
| 94 |
AN014 = 14, |
| 95 |
AN015 = 15, |
| 96 |
AN016 = 16, |
| 97 |
AN017 = 17, |
| 98 |
AN018 = 18, |
| 99 |
AN019 = 19, |
| 100 |
AN020 = 20, |
| 101 |
AN021 = 21, |
| 102 |
AN022 = 22, |
| 103 |
AN100 = 32, |
| 104 |
AN101 = 33, |
| 105 |
AN102 = 34, |
| 106 |
AN103 = 35, |
| 107 |
AN104 = 36, |
| 108 |
AN105 = 37, |
| 109 |
AN106 = 38, |
| 110 |
AN107 = 39, |
| 111 |
AN108 = 40, |
| 112 |
AN109 = 41, |
| 113 |
AN110 = 42, |
| 114 |
AN111 = 43, |
| 115 |
AN112 = 44, |
| 116 |
AN113 = 45, |
| 117 |
AN114 = 46, |
| 118 |
AN115 = 47, |
| 119 |
AN116 = 48, |
| 120 |
AN117 = 49, |
| 121 |
AN118 = 50, |
| 122 |
AN119 = 51, |
| 123 |
AN120 = 52, |
| 124 |
|
| 125 |
#elif defined(RA6M2) |
| 126 |
// Unit 0 |
| 127 |
AN000 = 0, |
| 128 |
AN001 = 1, |
| 129 |
AN002 = 2, |
| 130 |
AN003 = 3, |
| 131 |
AN004 = 4, |
| 132 |
AN005 = 5, |
| 133 |
AN006 = 6, |
| 134 |
AN007 = 7, |
| 135 |
AN016 = 16, |
| 136 |
AN017 = 17, |
| 137 |
AN018 = 18, |
| 138 |
AN019 = 19, |
| 139 |
AN020 = 20, |
| 140 |
// Unit 1 |
| 141 |
AN100 = 32, |
| 142 |
AN101 = 33, |
| 143 |
AN102 = 34, |
| 144 |
AN105 = 37, |
| 145 |
AN106 = 38, |
| 146 |
AN107 = 39, |
| 147 |
AN116 = 48, |
| 148 |
AN117 = 49, |
| 149 |
AN118 = 50, |
| 150 |
|
| 151 |
#elif defined(RA6M3) |
| 152 |
// Unit 0 |
| 153 |
AN000 = 0, |
| 154 |
AN001 = 1, |
| 155 |
AN002 = 2, |
| 156 |
AN003 = 3, |
| 157 |
AN004 = 4, |
| 158 |
AN005 = 5, |
| 159 |
AN006 = 6, |
| 160 |
AN007 = 7, |
| 161 |
AN016 = 16, |
| 162 |
AN017 = 17, |
| 163 |
AN018 = 18, |
| 164 |
AN019 = 19, |
| 165 |
AN020 = 20, |
| 166 |
// Unit 1 |
| 167 |
AN100 = 32, |
| 168 |
AN101 = 33, |
| 169 |
AN102 = 34, |
| 170 |
AN103 = 35, |
| 171 |
AN105 = 37, |
| 172 |
AN106 = 38, |
| 173 |
AN107 = 39, |
| 174 |
AN116 = 48, |
| 175 |
AN117 = 49, |
| 176 |
AN118 = 50, |
| 177 |
AN119 = 51, |
| 178 |
|
| 179 |
#elif defined(RA6M5) |
| 180 |
// Unit 0 |
| 181 |
AN000 = 0, |
| 182 |
AN001 = 1, |
| 183 |
AN002 = 2, |
| 184 |
AN003 = 3, |
| 185 |
AN004 = 4, |
| 186 |
AN005 = 5, |
| 187 |
AN006 = 6, |
| 188 |
AN007 = 7, |
| 189 |
AN008 = 8, |
| 190 |
AN009 = 9, |
| 191 |
AN010 = 10, |
| 192 |
AN012 = 12, |
| 193 |
AN013 = 13, |
| 194 |
// Unit 1 |
| 195 |
AN100 = 32, |
| 196 |
AN101 = 33, |
| 197 |
AN102 = 34, |
| 198 |
AN116 = 35, |
| 199 |
AN117 = 37, |
| 200 |
AN118 = 38, |
| 201 |
AN119 = 39, |
| 202 |
AN120 = 48, |
| 203 |
AN121 = 49, |
| 204 |
AN122 = 50, |
| 205 |
AN123 = 51, |
| 206 |
AN124 = 52, |
| 207 |
AN125 = 53, |
| 208 |
AN126 = 54, |
| 209 |
AN127 = 55, |
| 210 |
AN128 = 56, |
| 211 |
|
| 212 |
#else |
| 213 |
#error "CMSIS MCU Series is not specified." |
| 214 |
#endif |
| 215 |
ADC_TEMP = 29, |
| 216 |
ADC_REF = 30, |
| 217 |
ADC_NON = 255, |
| 218 |
}; |
| 219 |
|
| 220 |
#if defined(RA4M1) | defined(RA4W1) |
| 221 |
#define RA_ADC_DEF_RESOLUTION 14 |
| 222 |
#else |
| 223 |
#define RA_ADC_DEF_RESOLUTION 12 |
| 224 |
#endif |
| 225 |
|
| 226 |
bool ra_adc_pin_to_ch(uint32_t pin, uint8_t *ch); |
| 227 |
bool ra_adc_ch_to_pin(uint8_t ch, uint32_t *pin); |
| 228 |
uint8_t ra_adc_get_channel(uint32_t pin); |
| 229 |
// static void ra_adc_module_start(void); |
| 230 |
// static void ra_adc_module_stop(void); |
| 231 |
void ra_adc_set_pin(uint32_t pin, bool adc_enable); |
| 232 |
void ra_adc_enable(uint32_t pin); |
| 233 |
void ra_adc_disable(uint32_t pin); |
| 234 |
void ra_adc_set_resolution_set(uint8_t res); |
| 235 |
uint8_t ra_adc_get_resolution(void); |
| 236 |
uint16_t ra_adc_read_ch(uint8_t ch); |
| 237 |
uint16_t ra_adc_read(uint32_t pin); |
| 238 |
int16_t ra_adc_read_itemp(void); |
| 239 |
float ra_adc_read_ftemp(void); |
| 240 |
float ra_adc_read_fref(void); |
| 241 |
void ra_adc_all(uint32_t resolution, uint32_t mask); |
| 242 |
uint16_t ra_adc_all_read_ch(uint32_t ch); |
| 243 |
bool ra_adc_init(void); |
| 244 |
bool ra_adc_deinit(void); |
| 245 |
__attribute__((weak)) void adc_scan_end_isr(void); |
| 246 |
|
| 247 |
#endif /* RA_ADC_H_ */ |