File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -47,24 +47,25 @@ int8_t digitalPinToTouchChannel(uint8_t pin)
4747
4848int8_t digitalPinToAnalogChannel (uint8_t pin )
4949{
50- uint8_t channel ;
51- int8_t ret = -1 ;
50+ uint8_t channel = 0 ;
5251 if (pin < SOC_GPIO_PIN_COUNT ) {
5352 for (uint8_t i = 0 ; i < SOC_ADC_PERIPH_NUM ; i ++ ) {
5453 for (uint8_t j = 0 ; j < SOC_ADC_MAX_CHANNEL_NUM ; j ++ ) {
5554 if (adc_channel_io_map [i ][j ] == pin ) {
56- ret = channel ;
57- break ;
55+ return channel ;
5856 }
5957 channel ++ ;
6058 }
6159 }
6260 }
63- return ret ;
61+ return -1 ;
6462}
6563
6664int8_t analogChannelToDigitalPin (uint8_t channel )
6765{
66+ if (channel >= (SOC_ADC_PERIPH_NUM * SOC_ADC_MAX_CHANNEL_NUM )) {
67+ return -1 ;
68+ }
6869 uint8_t adc_unit = (channel / SOC_ADC_MAX_CHANNEL_NUM );
6970 uint8_t adc_chan = (channel % SOC_ADC_MAX_CHANNEL_NUM );
7071 return adc_channel_io_map [adc_unit ][adc_chan ];
You can’t perform that action at this time.
0 commit comments