Skip to content

Commit b44939c

Browse files
committed
fix bug #15
1 parent f3a7b1e commit b44939c

File tree

10 files changed

+43
-46
lines changed

10 files changed

+43
-46
lines changed

cores/arduino/Tone.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ extern pwm_fpio_set_t pwm_pins[VARIANT_NUM_PWM];
66

77
void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
88
{
9-
int8_t _pin = k210FpioSet(pin);
9+
int8_t _pin = k210FpioSet(MD_PIN_MAP(pin));
1010
if(_pin >= 0){
1111
if (duration > 0) {
1212
pwm_set_frequency(pwm_pins[_pin].device, pwm_pins[_pin].channel,(double)frequency,0.5);
@@ -24,7 +24,7 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
2424

2525
void noTone(uint8_t pin)
2626
{
27-
int8_t _pin = k210FpioSet(pin);
27+
int8_t _pin = k210FpioSet(MD_PIN_MAP(pin));
2828
if(_pin >= 0){
2929
pwm_set_enable(pwm_pins[_pin].device, pwm_pins[_pin].channel,0);
3030
}

cores/arduino/UARTClass.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ UARTClass::UARTClass(uart_device_number_t device_select)
6666
void
6767
UARTClass::begin(uint32_t dwBaudRate, uint8_t _rx, uint8_t _tx)
6868
{
69-
fpioa_set_function((int)_rx, this->_rxfunc);
70-
fpioa_set_function((int)_tx, this->_txfunc);
69+
fpioa_set_function((int)MD_PIN_MAP(_rx), this->_rxfunc);
70+
fpioa_set_function((int)MD_PIN_MAP(_tx), this->_txfunc);
7171
uart_init(this->_uart);
7272
uart_configure(this->_uart, dwBaudRate, UART_BITWIDTH_8BIT, UART_STOP_1, UART_PARITY_NONE);
7373
this->_buff = new RingBuffer();
@@ -144,8 +144,8 @@ UARTHSClass::UARTHSClass()
144144
void
145145
UARTHSClass::begin(uint32_t dwBaudRate, uint8_t _rx, uint8_t _tx)
146146
{
147-
fpioa_set_function((int)_rx, FUNC_UARTHS_RX);
148-
fpioa_set_function((int)_tx, FUNC_UARTHS_TX);
147+
fpioa_set_function((int)MD_PIN_MAP(_rx), FUNC_UARTHS_RX);
148+
fpioa_set_function((int)MD_PIN_MAP(_tx), FUNC_UARTHS_TX);
149149
uarths_init();
150150
uarths_config(dwBaudRate, UARTHS_STOP_1);
151151
this->_buff = new RingBuffer();

cores/arduino/WInterrupts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
void attachInterrupt(uint8_t intnum, voidFuncPtr user_callback, uint8_t mode)
77
{
8-
int gpionum = getGpio(intnum);
8+
int gpionum = get_gpio(MD_PIN_MAP(intnum));
99
if(gpionum >= 0){
1010
fpioa_function_t function = FUNC_GPIOHS0 + gpionum;
1111
fpioa_set_function(intnum, function);
@@ -34,7 +34,7 @@ void attachInterrupt(uint8_t intnum, voidFuncPtr user_callback, uint8_t mode)
3434

3535
void detachInterrupt(uint8_t intnum)
3636
{
37-
int gpionum = getGpio(intnum);
37+
int gpionum = get_gpio(MD_PIN_MAP(intnum));
3838
if(gpionum >= 0){
3939
gpiohs_irq_unregister((uint8_t)gpionum);
4040
}

cores/arduino/wiring_analog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void analogOutputInit(void)
5252

5353
void analogWrite(uint8_t ucPin, uint32_t ulValue )
5454
{
55-
int8_t _pin = k210FpioSet(ucPin);
55+
int8_t _pin = k210FpioSet(MD_PIN_MAP(ucPin));
5656
double _duty;
5757
if(_pin >= 0){
5858
_duty = dValueToDuty(ulValue);

cores/arduino/wiring_digital.c

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,43 @@
1313
extern "C"{
1414
#endif // __cplusplus
1515

16+
static int8_t _fpio_to_gpio_table[48]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
17+
1618
void pinMode(uint8_t dwPin, uint8_t dwMode){
17-
int gpionum = getGpio(dwPin);
19+
int gpionum = get_gpio(MD_PIN_MAP(dwPin));
1820
if(gpionum >= 0){
1921
fpioa_function_t function = FUNC_GPIOHS0 + gpionum;
20-
fpioa_set_function(dwPin, function);
22+
fpioa_set_function(MD_PIN_MAP(dwPin), function);
2123
gpiohs_set_drive_mode((uint8_t)gpionum, (gpio_drive_mode_t)dwMode);
2224
}
2325
return ;
2426
}
2527

2628
void digitalWrite(uint8_t dwPin, uint8_t dwVal){
27-
int gpionum = getGpio_s(dwPin);
28-
if(gpionum >= 0){
29-
gpiohs_set_pin((uint8_t)gpionum, (gpio_pin_value_t)dwVal);
29+
if(_fpio_to_gpio_table[MD_PIN_MAP(dwPin)] >= 0){
30+
gpiohs_set_pin((uint8_t)_fpio_to_gpio_table[MD_PIN_MAP(dwPin)], (gpio_pin_value_t)dwVal);
3031
}
3132
return ;
3233
}
3334

3435
int digitalRead(uint8_t dwPin){
35-
int gpionum = getGpio_s(dwPin);
36-
if(gpionum >= 0){
37-
return (int)gpiohs_get_pin((uint8_t)gpionum);
36+
if(_fpio_to_gpio_table[MD_PIN_MAP(dwPin)] >= 0){
37+
return (int)gpiohs_get_pin((uint8_t)_fpio_to_gpio_table[MD_PIN_MAP(dwPin)]);
3838
}
3939
return -1;
4040
}
4141

42-
int getGpio(uint8_t fpioPin) //分配一个gpio给fpio 输入 fpio 返回 gpiohs号
43-
{
44-
fpioa_function_t function = fpioa_get_function_buy_io(fpioPin);
45-
if(function <= FUNC_GPIOHS31 && function >= FUNC_GPIOHS0 )
46-
{
47-
return (int)(function - FUNC_GPIOHS0);
48-
}else{
49-
return find_unused_gpiohs_io();
50-
}
51-
}
52-
53-
int getGpio_s(uint8_t fpioPin)
42+
int get_gpio(uint8_t fpio_pin)
5443
{
55-
fpioa_function_t function = fpioa_get_function_buy_io(fpioPin);
56-
if(function <= FUNC_GPIOHS31 && function >= FUNC_GPIOHS0 )
57-
{
58-
return (int)(function - FUNC_GPIOHS0);
44+
if(_fpio_to_gpio_table[MD_PIN_MAP(fpio_pin)] > -1){
45+
return _fpio_to_gpio_table[MD_PIN_MAP(fpio_pin)];
5946
}else{
60-
return -1;
47+
_fpio_to_gpio_table[MD_PIN_MAP(fpio_pin)] = find_unused_gpiohs_io();
48+
return _fpio_to_gpio_table[MD_PIN_MAP(fpio_pin)];
6149
}
6250
}
6351

64-
fpioa_function_t fpioa_get_function_buy_io(uint8_t fpioPin)
52+
fpioa_function_t fpioa_get_function_by_io(uint8_t fpioPin)
6553
{
6654
return (fpioa_function_t)fpioa->io[fpioPin].ch_sel ;
6755
}

cores/arduino/wiring_digital.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ extern void digitalWrite( uint8_t dwPin, uint8_t dwVal ) ;
5353
*/
5454
extern int digitalRead( uint8_t dwPin ) ;
5555

56-
int getGpio(uint8_t fpioPin) ;
57-
int getGpio_s(uint8_t fpioPin) ;
58-
fpioa_function_t fpioa_get_function_buy_io(uint8_t fpioPin) ;
56+
int get_gpio(uint8_t fpio_pin) ;
57+
fpioa_function_t fpioa_get_function_by_io(uint8_t fpioPin) ;
5958
int find_unused_gpiohs_io(void) ;
6059

6160
#ifdef __cplusplus

variants/sipeed_maix_bit/pins_arduino.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _VARIANT_SIPEED_M1_DOCK
2-
#define _VARIANT_SIPEED_M1_DOCK
1+
#ifndef _VARIANT_SIPEED_MAIX_BIT
2+
#define _VARIANT_SIPEED_MAIX_BIT
33

44
#include <stdint.h>
55

@@ -58,6 +58,8 @@ extern class UARTClass Serial3;
5858
#define SDA 31
5959
#define SCL 30
6060

61+
#define MD_PIN_MAP(fpio) (fpio)
62+
6163
static const uint8_t SS = SPI0_CS0 ;
6264
static const uint8_t MOSI = SPI0_MOSI;
6365
static const uint8_t MISO = SPI0_MISO;

variants/sipeed_maix_go/pins_arduino.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ extern class UARTClass Serial3;
6565
#define SDA 31
6666
#define SCL 30
6767

68+
#define MD_PIN_MAP(fpio) (fpio)
69+
6870
static const uint8_t SS = SPI0_CS0 ;
6971
static const uint8_t MOSI = SPI0_MOSI;
7072
static const uint8_t MISO = SPI0_MISO;

variants/sipeed_maix_one_dock/pins_arduino.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ extern class UARTClass Serial3;
6565
#define SDA 31
6666
#define SCL 30
6767

68+
#define MD_PIN_MAP(fpio) (fpio)
69+
6870
static const uint8_t SS = SPI0_CS0 ;
6971
static const uint8_t MOSI = SPI0_MOSI;
7072
static const uint8_t MISO = SPI0_MISO;

variants/sipeed_maixduino/pins_arduino.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef _VARIANT_SIPEED_M1_DOCK
2-
#define _VARIANT_SIPEED_M1_DOCK
1+
#ifndef _VARIANT_SIPEED_MAIXDUINO
2+
#define _VARIANT_SIPEED_MAIXDUINO
33

44
#include <stdint.h>
55

@@ -56,8 +56,8 @@ extern class UARTClass Serial3;
5656
#define LCD_DC 38
5757
#define LCD_WR 39
5858

59-
#define RX0 4
60-
#define TX0 5
59+
#define RX0 0
60+
#define TX0 1
6161

6262
#define RX1 6
6363
#define TX1 7
@@ -76,9 +76,13 @@ typedef struct _pwm_fpio_set_t{
7676
uint8_t inuse;
7777
}pwm_fpio_set_t;
7878

79-
static uint8_t maixduino_pin_map[14] = {4, 5, 21, 22, 23, 24, 32, 15, 14, 13, 12, 11, 10, 3};
79+
#define MD_PIN_MAP(fpio) _maixduino_pin_map[(fpio)]
80+
81+
uint8_t _maixduino_pin_map[14] = {4, 5, 21, 22, 23, 24, 32, 15, 14, 13, 12, 11, 10, 3};
82+
83+
84+
uint8_t pinToFpio(uint8_t pin){ return MD_PIN_MAP(pin); }
8085

81-
uint8_t pinToFpio(uint8_t pin){ return maixduino_pin_map[pin]; }
8286

8387
typedef enum _analog_output_pin_t{
8488
A0,

0 commit comments

Comments
 (0)