Skip to content

Commit 0e3ab20

Browse files
author
Khalil Estell
authored
♻️ Alias adaptor factor in hal namespace (#44)
1 parent 2924d0f commit 0e3ab20

4 files changed

Lines changed: 33 additions & 49 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ name: ✅ CI
1717
on:
1818
workflow_dispatch:
1919
pull_request:
20+
release:
21+
types: [published]
2022
push:
21-
tags:
22-
- "*"
2323
branches:
2424
- main
2525
schedule:
@@ -36,14 +36,3 @@ jobs:
3636
devices:
3737
uses: libhal/ci/.github/workflows/deploy.yml@4.1.0
3838
secrets: inherit
39-
40-
release:
41-
needs: [ci, devices]
42-
if: startsWith(github.ref, 'refs/tags/')
43-
runs-on: ubuntu-22.04
44-
steps:
45-
- name: Release
46-
uses: softprops/action-gh-release@v1
47-
if: startsWith(github.ref, 'refs/tags/')
48-
with:
49-
generate_release_notes: true

include/libhal-soft/adc_mux.hpp

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,6 @@
2121
#include <libhal/output_pin.hpp>
2222
#include <libhal/steady_clock.hpp>
2323

24-
namespace hal::soft {
25-
class adc_multiplexer;
26-
class adc_mux_pin;
27-
} // namespace hal::soft
28-
29-
namespace hal::make {
30-
/**
31-
* @brief Returns an ADC pin from the multiplexer.
32-
*
33-
* @param p_multiplexer the adc multiplexer with the desire adc channel pin
34-
* @param p_channel The channel number of the pin
35-
* @return A newly constructed ADC multiplexer pin.
36-
* @throws std::errc::
37-
*/
38-
result<hal::soft::adc_mux_pin> adc(hal::soft::adc_multiplexer& p_multiplexer,
39-
std::uint8_t p_channel);
40-
} // namespace hal::make
41-
4224
namespace hal::soft {
4325
/**
4426
* @brief A driver for an ADC multiplexer that manages and reads ADC mux pins.
@@ -75,7 +57,7 @@ class adc_multiplexer
7557

7658
/**
7759
* @brief Gets the highest capacity channel held by the ADC mux object.
78-
* This is caluclated based off of how many source pins are available.
60+
* This is calculated based off of how many source pins are available.
7961
*
8062
* @return The maximum channel number for this mux (2^n states, where n is
8163
* number of source pins).
@@ -98,9 +80,8 @@ class adc_multiplexer
9880
*/
9981
class adc_mux_pin : public hal::adc
10082
{
101-
friend hal::result<adc_mux_pin>(
102-
::hal::make::adc(hal::soft::adc_multiplexer& p_multiplexer,
103-
std::uint8_t p_channel));
83+
friend hal::result<adc_mux_pin> make_adc(adc_multiplexer& p_multiplexer,
84+
std::uint8_t p_channel);
10485

10586
private:
10687
adc_mux_pin(adc_multiplexer& p_mux, std::uint8_t p_mux_port);
@@ -109,4 +90,20 @@ class adc_mux_pin : public hal::adc
10990
adc_multiplexer* m_mux;
11091
std::uint8_t m_mux_port;
11192
};
93+
94+
/**
95+
* @brief Returns an ADC pin from the multiplexer.
96+
*
97+
* @param p_multiplexer the adc multiplexer with the desire adc channel pin
98+
* @param p_channel The channel number of the pin
99+
* @return A newly constructed ADC multiplexer pin.
100+
* @throws std::errc::result_out_of_range if p_channel greater than the
101+
* available number of channels in the multiplexer.
102+
*/
103+
result<adc_mux_pin> make_adc(adc_multiplexer& p_multiplexer,
104+
std::uint8_t p_channel);
112105
} // namespace hal::soft
106+
107+
namespace hal {
108+
using hal::soft::make_adc;
109+
} // namespace hal

src/adc_mux.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,13 @@ hal::result<hal::adc::read_t> adc_mux_pin::driver_read()
6868
{
6969
return m_mux->read_channel(m_mux_port);
7070
}
71-
} // namespace hal::soft
7271

73-
namespace hal::make {
74-
result<hal::soft::adc_mux_pin> adc(hal::soft::adc_multiplexer& p_multiplexer,
75-
std::uint8_t p_channel)
72+
result<adc_mux_pin> make_adc(adc_multiplexer& p_multiplexer,
73+
std::uint8_t p_channel)
7674
{
7775
if (p_channel > p_multiplexer.get_max_channel()) {
7876
return hal::new_error(std::errc::result_out_of_range);
7977
}
80-
return hal::soft::adc_mux_pin(p_multiplexer, p_channel);
78+
return adc_mux_pin(p_multiplexer, p_channel);
8179
}
82-
} // namespace hal::make
80+
} // namespace hal::soft

tests/adc_mux.test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void adc_mux_test()
7373
// Setup
7474
adc_multiplexer test_mux =
7575
adc_multiplexer::create(signal_pins, source_adc, mock_timer);
76-
adc_mux_pin test_adc_port_zero = hal::make::adc(test_mux, 0).value();
76+
adc_mux_pin test_adc_port_zero = hal::make_adc(test_mux, 0).value();
7777
constexpr float expected_sample_zero = 0;
7878

7979
// Exercise
@@ -88,8 +88,8 @@ void adc_mux_test()
8888
// Setup
8989
adc_multiplexer test_mux =
9090
adc_multiplexer::create(signal_pins, source_adc, mock_timer);
91-
adc_mux_pin first_mux_pin = hal::make::adc(test_mux, 1).value();
92-
adc_mux_pin second_mux_pin = hal::make::adc(test_mux, 2).value();
91+
adc_mux_pin first_mux_pin = hal::make_adc(test_mux, 1).value();
92+
adc_mux_pin second_mux_pin = hal::make_adc(test_mux, 2).value();
9393
constexpr float expected_sample_zero = 0;
9494
constexpr float expected_sample_three_halves = 1.5;
9595

@@ -123,12 +123,12 @@ void adc_mux_test()
123123

124124
// Exercise
125125
auto test_read_data = std::array<hal::result<hal::adc::read_t>, 4>{
126-
hal::make::adc(test_mux, 0).value().read(),
127-
hal::make::adc(test_mux, 1).value().read(),
128-
hal::make::adc(test_mux, 2).value().read(),
129-
hal::make::adc(test_mux, 3).value().read()
126+
hal::make_adc(test_mux, 0).value().read(),
127+
hal::make_adc(test_mux, 1).value().read(),
128+
hal::make_adc(test_mux, 2).value().read(),
129+
hal::make_adc(test_mux, 3).value().read()
130130
};
131-
auto error_test = hal::make::adc(test_mux, 4).value().read();
131+
auto error_test = hal::make_adc(test_mux, 4).value().read();
132132

133133
// Verify
134134
for (auto& p : test_read_data) {

0 commit comments

Comments
 (0)