Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MateControllerDevice base class for interfacing with devices atta…
…ched to a MATE bus
- Loading branch information
Showing
6 changed files
with
168 additions
and
29 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
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,50 @@ | ||
#ifndef MATE_CONTROLLER_DEVICE_H | ||
#define MATE_CONTROLLER_DEVICE_H | ||
|
||
class MateControllerDevice { | ||
public: | ||
MateControllerDevice( | ||
MateControllerProtocol& protocol, | ||
DeviceType dtype | ||
) : | ||
protocol(protocol), | ||
dtype(dtype), | ||
port(-1), | ||
is_open(false) | ||
{ } | ||
|
||
// Open a device on the specified port. | ||
// returns false if the device is not present on that port. | ||
bool begin(uint8_t port) { | ||
is_open = (protocol.scan(port) == dtype); | ||
return is_open; | ||
} | ||
|
||
// Query a register and retrieve its value (BLOCKING) | ||
// reg: The register address | ||
// param: Optional parameter | ||
// returns: The register value | ||
uint16_t query(uint16_t reg, uint16_t param = 0) { | ||
return protocol.query(reg, param, this->port); | ||
} | ||
|
||
// Control something (BLOCKING) | ||
// reg: The control address | ||
// value: The value to use for controlling (eg. disable/enable) | ||
void control(uint16_t reg, uint16_t value) { | ||
protocol.control(reg, value, this->port); | ||
} | ||
|
||
// Read the revision from the target device | ||
revision_t get_revision() { | ||
protocol.get_revision(this->port); | ||
} | ||
|
||
protected: | ||
MateControllerProtocol& protocol; | ||
DeviceType dtype; | ||
int8_t port; | ||
bool is_open; | ||
}; | ||
|
||
#endif /* MATE_CONTROLLER_DEVICE_H */ |
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
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