-
Notifications
You must be signed in to change notification settings - Fork 2
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
✨ Add tla2528 driver #5
base: main
Are you sure you want to change the base?
Conversation
currently, the reset command is declared as a private method but is unimplemented. Should it be removed? or is it better to leave it there for the binary interface consistency (I'm not sure how ABIs work) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Much of my comments have to do with formatting and documentation. The rest mostly looks good.
|
||
#include <array> | ||
#include <libhal-util/bit.hpp> | ||
#include <libhal-util/i2c.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/input_pin.hpp> | ||
#include <libhal/units.hpp> | ||
#include <libhal-expander/tla2528.hpp> | ||
|
||
#include <libhal-expander/tla2528_adapters.hpp> | ||
#include <resource_list.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <array> | |
#include <libhal-util/bit.hpp> | |
#include <libhal-util/i2c.hpp> | |
#include <libhal-util/serial.hpp> | |
#include <libhal-util/steady_clock.hpp> | |
#include <libhal/input_pin.hpp> | |
#include <libhal/units.hpp> | |
#include <libhal-expander/tla2528.hpp> | |
#include <libhal-expander/tla2528_adapters.hpp> | |
#include <resource_list.hpp> | |
#include <array> | |
#include <libhal-util/bit.hpp> | |
#include <libhal-util/i2c.hpp> | |
#include <libhal-util/serial.hpp> | |
#include <libhal-util/steady_clock.hpp> | |
#include <libhal/input_pin.hpp> | |
#include <libhal/units.hpp> | |
#include <libhal-expander/tla2528.hpp> | |
#include <libhal-expander/tla2528_adapters.hpp> | |
#include <resource_list.hpp> |
Suggestion made based on https://libhal.github.io/4.1/contributor_guide/style/#s143-include-order.
} | ||
hal::delay(steady_clock, 500ms); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All files should end with a newline. I'm adding a patch to have CI check demos directory files as well.
#include <array> | ||
#include <libhal-util/bit.hpp> | ||
#include <libhal-util/i2c.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/input_pin.hpp> | ||
#include <libhal/units.hpp> | ||
#include <libhal-expander/tla2528.hpp> | ||
#include <libhal-expander/tla2528_adapters.hpp> | ||
#include <resource_list.hpp> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <array> | |
#include <libhal-util/bit.hpp> | |
#include <libhal-util/i2c.hpp> | |
#include <libhal-util/serial.hpp> | |
#include <libhal-util/steady_clock.hpp> | |
#include <libhal/input_pin.hpp> | |
#include <libhal/units.hpp> | |
#include <libhal-expander/tla2528.hpp> | |
#include <libhal-expander/tla2528_adapters.hpp> | |
#include <resource_list.hpp> | |
#include <array> | |
#include <libhal-util/bit.hpp> | |
#include <libhal-util/i2c.hpp> | |
#include <libhal-util/serial.hpp> | |
#include <libhal-util/steady_clock.hpp> | |
#include <libhal/input_pin.hpp> | |
#include <libhal/units.hpp> | |
#include <libhal-expander/tla2528.hpp> | |
#include <libhal-expander/tla2528_adapters.hpp> | |
#include <resource_list.hpp> | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this everywhere else as well.
/** | ||
* @brief create a hal::input_pin driver using the tla2528 driver | ||
* | ||
* @param p_channel pin acting as an input pin | ||
* | ||
* @param p_settings input pin settings, default is no resistor | ||
* | ||
* @throws hal::argument_out_of_domain - if p_channel out of range (>7) | ||
* | ||
* @throws hal::resource_unavailable_try_again - if an adapter has already been | ||
* been made for the pin | ||
* | ||
* @throws hal::no_such_device - no device responded on i2c bus | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* @brief create a hal::input_pin driver using the tla2528 driver | |
* | |
* @param p_channel pin acting as an input pin | |
* | |
* @param p_settings input pin settings, default is no resistor | |
* | |
* @throws hal::argument_out_of_domain - if p_channel out of range (>7) | |
* | |
* @throws hal::resource_unavailable_try_again - if an adapter has already been | |
* been made for the pin | |
* | |
* @throws hal::no_such_device - no device responded on i2c bus | |
*/ | |
/** | |
* @brief create a hal::input_pin driver using the tla2528 driver | |
* | |
* @param p_channel pin acting as an input pin | |
* @param p_settings input pin settings, default is no resistor | |
* @throws hal::argument_out_of_domain - if p_channel out of range (>7) | |
* @throws hal::resource_unavailable_try_again - if an adapter has already been | |
* been made for the pin | |
* @throws hal::no_such_device - no device responded on i2c bus | |
*/ |
I find the spacing harder to read than keeping everything together. Can you make this change to other comments like this as well.
*/ | ||
tla2528_input_pin make_input_pin(tla2528& p_tla2528, | ||
hal::byte p_channel, | ||
hal::input_pin::settings const& p_settings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hal::input_pin::settings const& p_settings); | |
hal::input_pin::settings const& p_settings = {.resistor = none}); |
May be a nice QOL feature to have this have a default settings parameter vs having the user have to supply each.
float tla2528::get_analog_in(hal::byte p_channel) | ||
{ | ||
set_analog_channel(p_channel); | ||
// TODO: look into averaging & channel validation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: look into averaging & channel validation | |
// TODO(#issue): look into averaging & channel validation |
Make an issue for this.
if (hal::bit_extract(hal::bit_mask::from(m_channel), | ||
m_tla2528->m_object_created)) { | ||
throw hal::resource_unavailable_try_again(this); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use this same logic a few times in the adaptors. Would make sense to make a helper function for this.
: m_i2c_bus(p_i2c) | ||
, m_i2c_address(p_i2c_address) | ||
{ | ||
// TODO: reset command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO: reset command | |
// TODO(#issue-number): reset command |
Make an technical debt issue for this. Also you might as well call reset() here and define it with the TODO. That way the code is already in place and the empty function has the todo embedded in it.
hal::byte counter = | ||
0; // output counts in binary to go though all out put combinations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hal::byte counter = | |
0; // output counts in binary to go though all out put combinations | |
// output counts in binary to go though all out put combinations | |
hal::byte counter = 0; |
The newline 0 looks really odd. You can put the comment one line above.
tla2528_output_pin::~tla2528_output_pin() | ||
{ | ||
hal::bit_modify(m_tla2528->m_object_created) | ||
.set(hal::bit_mask::from(m_channel)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.set(hal::bit_mask::from(m_channel)); | |
.clear(hal::bit_mask::from(m_channel)); |
Shouldn't this be clear?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do the same for the others.
See my comment on what you should do about reset. As for ABI, class functions do not effect the ABI of a function so nothing to worry about from that angle. |
The tla2528 is an i2c-based GPIO expander and ADC mux. It has 8 pins that can each be independently configured and operated as GPIO or ADC. This is a port of the tla2528 driver and adapters from the SJSU robotics team.
Features
Missing/future/unimplemented features: