This repository has been archived by the owner on Aug 18, 2024. It is now read-only.
forked from libhal-google/libhal-stm32f4
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Add Input Pins * 🔖 Add 1.0.0.yml
- Loading branch information
Showing
9 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,5 @@ jobs: | |
uses: ./.github/workflows/deploy-version.yml | ||
with: | ||
version: 0.0.1 | ||
secrets: inherit | ||
secrets: inherit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: 🚀 Release 1.0.0 | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
uses: ./.github/workflows/deploy-version.yml | ||
with: | ||
version: 1.0.0 | ||
secrets: inherit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ project(demos LANGUAGES CXX) | |
libhal_build_demos( | ||
DEMOS | ||
blinker | ||
button | ||
|
||
PACKAGES | ||
libhal-stm32f4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <libhal-armcortex/dwt_counter.hpp> | ||
|
||
#include <libhal-stm32f4/input_pin.hpp> | ||
#include <libhal-stm32f4/output_pin.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/units.hpp> | ||
|
||
// TODO(#15): Replace with `hal::cortex_m::dwt_counter` | ||
|
||
void delay_by_cycles(int p_cycles) | ||
{ | ||
volatile int i = 0; | ||
while (i < p_cycles) { | ||
i = i + 1; | ||
} | ||
} | ||
|
||
void application() | ||
{ | ||
hal::stm32f4::input_pin button(hal::stm32f4::peripheral::gpio_c, | ||
13, | ||
{ .resistor = hal::pin_resistor::pull_up }); | ||
hal::stm32f4::output_pin led(hal::stm32f4::peripheral::gpio_a, 5); | ||
bool led_val = false; | ||
while (true) { | ||
if (!button.level()) { | ||
led_val = !led_val; | ||
} | ||
led.level(led_val); | ||
delay_by_cycles(200000); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <libhal/input_pin.hpp> | ||
|
||
#include "pin.hpp" | ||
|
||
namespace hal::stm32f4 { | ||
/** | ||
* @brief Input pin implementation for the stm32f4 | ||
* | ||
*/ | ||
class input_pin : public hal::input_pin | ||
{ | ||
public: | ||
/** | ||
* @brief Construct a new input pin object | ||
* | ||
* @param p_port - selects pin port to use | ||
* @param p_pin - selects pin within the port to use | ||
* @param p_settings - initial pin settings | ||
*/ | ||
input_pin(hal::stm32f4::peripheral p_port, | ||
std::uint8_t p_pin, | ||
const input_pin::settings& p_settings = {}); | ||
|
||
input_pin(input_pin& p_other) = delete; | ||
input_pin& operator=(input_pin& p_other) = delete; | ||
input_pin(input_pin&& p_other) noexcept = delete; | ||
input_pin& operator=(input_pin&& p_other) noexcept = delete; | ||
~input_pin() = default; | ||
|
||
private: | ||
void driver_configure(const settings& p_settings) override; | ||
bool driver_level() override; | ||
|
||
hal::stm32f4::peripheral m_port{}; | ||
uint8_t m_pin{}; | ||
}; | ||
} // namespace hal::stm32f4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <cstdint> | ||
|
||
#include <libhal-stm32f4/input_pin.hpp> | ||
|
||
#include "gpio_reg.hpp" | ||
#include "power.hpp" | ||
#include <libhal-util/bit.hpp> | ||
|
||
#include "gpio_reg.hpp" | ||
|
||
namespace hal::stm32f4 { | ||
input_pin::input_pin(hal::stm32f4::peripheral p_port, | ||
std::uint8_t p_pin, | ||
const settings& p_settings) | ||
: m_port(p_port) | ||
, m_pin(p_pin) | ||
{ | ||
power(p_port).on(); | ||
input_pin::driver_configure(p_settings); | ||
} | ||
|
||
void input_pin::driver_configure(const settings& p_settings) | ||
{ | ||
bit_mask pin_mode_mask = { .position = 2 * static_cast<uint32_t>(m_pin), | ||
.width = 2 }; | ||
|
||
bit_modify(get_reg(m_port)->pin_mode).clear(pin_mode_mask); | ||
|
||
pin(m_port, m_pin) | ||
.function(pin::pin_function::input) | ||
.open_drain(false) | ||
.resistor(p_settings.resistor); | ||
} | ||
|
||
bool input_pin::driver_level() | ||
{ | ||
bit_mask input_data_mask = { .position = static_cast<uint32_t>(m_pin), | ||
.width = 1 }; | ||
auto pin_value = bit_extract(input_data_mask, get_reg(m_port)->input_data); | ||
return static_cast<bool>(pin_value); | ||
} | ||
} // namespace hal::stm32f4 |