Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[p2][photon2] Add VBAT_MEAS pin and charging indication pin for Photon2 #2482

Merged
merged 3 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions hal/src/rtl872x/gpio_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ bool isCachePin(hal_pin_t pin) {
return false;
}

bool isGpioPin(hal_pin_t pin) {
hal_pin_info_t* pinInfo = hal_pin_map() + pin;
return(pinInfo->gpio_port != RTL_PORT_NONE) ? true : false;
}

bool isCachePinSetToOutput(hal_pin_t pin) {
hal_pin_info_t* pinInfo = hal_pin_map() + pin;
if ((pinInfo->pin_mode == OUTPUT) ||
Expand Down Expand Up @@ -100,6 +105,7 @@ void hal_gpio_mode(hal_pin_t pin, PinMode mode) {

int hal_gpio_configure(hal_pin_t pin, const hal_gpio_config_t* conf, void* reserved) {
CHECK_TRUE(hal_pin_is_valid(pin), SYSTEM_ERROR_INVALID_ARGUMENT);
CHECK_TRUE(isGpioPin(pin), SYSTEM_ERROR_NOT_SUPPORTED);
CHECK_TRUE(conf, SYSTEM_ERROR_INVALID_ARGUMENT);

hal_pin_info_t* pinInfo = hal_pin_map() + pin;
Expand Down Expand Up @@ -218,7 +224,7 @@ PinMode hal_gpio_get_mode(hal_pin_t pin) {
}

void hal_gpio_write(hal_pin_t pin, uint8_t value) {
if (!hal_pin_is_valid(pin)) {
if (!hal_pin_is_valid(pin) || !isGpioPin(pin)) {
return;
}

Expand Down Expand Up @@ -252,7 +258,7 @@ void hal_gpio_write(hal_pin_t pin, uint8_t value) {
}

int32_t hal_gpio_read(hal_pin_t pin) {
if (!hal_pin_is_valid(pin)) {
if (!hal_pin_is_valid(pin) || !isGpioPin(pin)) {
return 0;
}

Expand Down Expand Up @@ -304,7 +310,7 @@ uint32_t hal_gpio_pulse_in(hal_pin_t pin, uint16_t value) {
const uint64_t THREE_SECONDS_IN_MICROSECONDS = 3000000;
#define FAST_READ(pin) ((gpiobase->EXT_PORT[0] >> pin) & 1UL)

if (!hal_pin_is_valid(pin)) {
if (!hal_pin_is_valid(pin) || !isGpioPin(pin)) {
return 0;
}

Expand Down
11 changes: 6 additions & 5 deletions hal/src/tron/pinmap_defines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ static hal_pin_info_t pinmap[TOTAL_PINS] = {
/* S6 - 21 */ { RTL_PORT_B, 31, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, 0},

/* System space */
/* RGBR - 22 */ { RTL_PORT_A, 30, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 1, 0},
/* RGBG - 23 */ { RTL_PORT_B, 23, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 3, 0},
/* RGBB - 24 */ { RTL_PORT_B, 22, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 2, 0},
/* MODE BUTTON - 25 */ { RTL_PORT_A, 4, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, 0},
/* ANTSW - 26 */ { RTL_PORT_A, 2, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, 0},
/* RGBR - 22 */ { RTL_PORT_A, 30, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 1, 0},
/* RGBG - 23 */ { RTL_PORT_B, 23, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 3, 0},
/* RGBB - 24 */ { RTL_PORT_B, 22, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, 0, 2, 0},
/* MODE BUTTON - 25 */ { RTL_PORT_A, 4, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, 0},
/* ANTSW - 26 */ { RTL_PORT_A, 2, PIN_MODE_NONE, PF_NONE, ADC_CHANNEL_NONE, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, 0},
/* VBAT_MEAS/A6 - 27 */ { RTL_PORT_NONE, 0, PIN_MODE_NONE, PF_NONE, 7, PWM_INSTANCE_NONE, PWM_CHANNEL_NONE, 0},
};

} // anonymous
Expand Down
6 changes: 5 additions & 1 deletion hal/src/tron/pinmap_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#pragma once

#define TOTAL_PINS 27
#define TOTAL_PINS 28
#define TOTAL_ANALOG_PINS 6
#define FIRST_ANALOG_PIN 11

Expand Down Expand Up @@ -60,6 +60,7 @@
#define A3 D0
#define A4 D1
#define A5 D14
#define A6 27 // VBAT_MEAS on Photon2, when used as an analog pin

// RGB and Button
#define RGBR 22
Expand Down Expand Up @@ -99,3 +100,6 @@
#define WKP D10

#define ANTSW 26

// Read-only charge indicator pin for Photon2
#define CHG S5