Skip to content

Commit 414863f

Browse files
committed
pin_enable_feature rename, and pinMode fix
1 parent f66144a commit 414863f

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

cores/arduino/Arduino.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ uint8_t analogReadResolution();
120120

121121
gpio_set(pin, pin_status);
122122
// Set pin mode on every write (Arduino version does this)
123+
pin_enable_function(pin, LPC176x::Function::GPIO);
123124
gpio_set_output(pin);
124125
}
125126
[[gnu::always_inline, gnu::optimize("O3")]] inline bool digitalRead(const pin_t pin) {

cores/arduino/HardwarePWM.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class HardwarePWM {
2828
// return the bits to attach the PWM hardware depending on port using a lookup table
29-
[[nodiscard]] static constexpr int8_t pwm_feature_index(const pin_t pin) noexcept {
29+
[[nodiscard]] static constexpr int8_t pwm_function_index(const pin_t pin) noexcept {
3030
constexpr std::array<int8_t, 5> lookup {-1, 2, 1, 3, -1};
3131
return lookup[pin_port(pin)];
3232
}
@@ -65,7 +65,7 @@ class HardwarePWM {
6565
static inline void set_idle(const pin_t pin) {
6666
gpio_set_output(pin); // used when at 0 duty cycle
6767
util::bit_set(idle_pins, get_pin_id(pin)); // mark pin as inactive
68-
pin_enable_feature(pin, 0);
68+
pin_enable_function(pin, LPC176x::Function::GPIO);
6969
gpio_clear(pin);
7070
}
7171

@@ -148,7 +148,7 @@ class HardwarePWM {
148148
if(value == 0) {
149149
set_idle(pin);
150150
} else if(util::bit_test(idle_pins, get_pin_id(pin))) {
151-
pin_enable_feature(pin, pwm_feature_index(pin));
151+
pin_enable_function(pin, pwm_function_index(pin));
152152
util::bit_clear(idle_pins, get_pin_id(pin));
153153
}
154154
}
@@ -162,7 +162,7 @@ class HardwarePWM {
162162

163163
static inline bool detach(const pin_t pin) {
164164
if (active(pin)) {
165-
pin_enable_feature(pin, 0); // reenable gpio
165+
pin_enable_function(pin, LPC176x::Function::GPIO); // reenable gpio
166166
gpio_clear(pin);
167167
deactivate_channel(pin);
168168
return true;

cores/arduino/SoftwarePWM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class SoftwarePWM {
216216
if (data_table.update(pin, value)) {
217217
gpio_set_output(pin);
218218
gpio_clear(pin);
219-
pin_enable_feature(pin, 0); // initialise pin for gpio output
219+
pin_enable_function(pin, LPC176x::Function::GPIO); // initialise pin for gpio output
220220
return true;
221221
}
222222
return false;

cores/arduino/Tone.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void tone(const pin_t _pin, const uint32_t frequency, const uint32_t duration =
2626
LPC_TIM2->MR0 = (1000000 / (2 * frequency)) - 1; // Match value (period) to set frequency
2727
LPC_TIM2->TCR = util::bit_value(0); // Counter Enable
2828

29-
pin_enable_feature(_pin, 0);
29+
pin_enable_function(_pin, LPC176x::Function::GPIO);
3030
gpio_set_output(_pin);
3131
gpio_clear(_pin);
3232

cores/arduino/arduino.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ void delay(const int msec) {
6666
// As defined by Arduino INPUT(0x0), OUTPUT(0x1), INPUT_PULLUP(0x2)
6767
void pinMode(const pin_t pin, const uint8_t mode) {
6868
if (!pin_is_valid(pin)) return;
69+
pin_enable_function(pin, LPC176x::Function::GPIO);
6970
if(mode == OUTPUT) {
7071
gpio_set_output(pin);
7172
pin_set_mode(pin, PinMode::TRISTATE);

system/lpc176x/pin_control.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ namespace LPC176x {
1414
OPENDRAIN,
1515
};
1616

17+
enum Function : uint8_t {
18+
GPIO,
19+
FUNC1,
20+
FUNC2,
21+
FUNC3,
22+
};
23+
1724
struct pin_type {
1825
struct gpio_block {
1926
uint32_t reg_dir; // 0x00
@@ -347,6 +354,6 @@ using LPC176x::PinMode;
347354
LPC176x::pin_type{pin}.enable_pwm();
348355
}
349356

350-
[[gnu::always_inline]] inline void pin_enable_feature(const pin_t pin, uint8_t feature) {
351-
LPC176x::pin_type{pin}.function(feature);
357+
[[gnu::always_inline]] inline void pin_enable_function(const pin_t pin, uint8_t function) {
358+
LPC176x::pin_type{pin}.function(function);
352359
}

0 commit comments

Comments
 (0)