Skip to content

Commit

Permalink
Add status code/get call to SAI and children classes
Browse files Browse the repository at this point in the history
Move to public inheritance of SAI in children

Allows access to general member methods like status.

Moved internal functions to protected

Cherry-picked examples.json changes that limited Lorawan example tests to Lorawan targets
  • Loading branch information
kegilbert authored and ithinuel committed Jun 12, 2018
1 parent 5f302f1 commit 0b8fceb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
8 changes: 5 additions & 3 deletions drivers/SAI.cpp
Expand Up @@ -38,9 +38,7 @@ SAI::SAI(PinName mclk, PinName bclk, PinName wclk, PinName sd,

init.format = *fmt;

if (sai_init(&_sai, &init) != SAI_RESULT_OK) {
// it failed :o
}
_status = sai_init(&_sai, &init);
}

bool SAI::xfer(uint32_t *value) {
Expand All @@ -50,6 +48,10 @@ bool SAI::xfer(uint32_t *value) {
return ret;
}

sai_result_t SAI::status(void) {
return _status;
}

void SAI::lock() {
_mutex.lock();
}
Expand Down
19 changes: 12 additions & 7 deletions drivers/SAI.h
Expand Up @@ -41,11 +41,19 @@ class SAI : private NonCopyable<SAI> {
const sai_format_t *fmt = &sai_mode_i2s32, bool is_input = false,
uint32_t master_clock = 0, bool internal_mclk = false);

/** Retreive the object status. Allows the ctor to
* funnel init errors/warnings back up to the application.
*/
virtual sai_result_t status(void);

/** Push a sample to the Fifo & try to read a new sample.
* it may return 0 if no sample was available.
*/
virtual bool xfer(uint32_t *value);

virtual ~SAI() {}

protected:
/** Acquire exclusive access to this SAI bus
*/
virtual void lock(void);
Expand All @@ -54,17 +62,14 @@ class SAI : private NonCopyable<SAI> {
*/
virtual void unlock(void);


public:
virtual ~SAI() {}

protected:
////////////////////////////////////////////
sai_t _sai;
PlatformMutex _mutex;
bool _is_input;
sai_result_t _status;
};

class SAITransmitter : private SAI {
class SAITransmitter : public SAI {
public:
SAITransmitter(PinName mclk, PinName bclk, PinName wclk, PinName sd,
const sai_format_t *fmt = &sai_mode_i2s32)
Expand All @@ -75,7 +80,7 @@ class SAITransmitter : private SAI {
}
};

class SAIReceiver : private SAI {
class SAIReceiver : public SAI {
public:
SAIReceiver(PinName mclk, PinName bclk, PinName wclk, PinName sd,
const sai_format_t *fmt = &sai_mode_i2s32)
Expand Down

0 comments on commit 0b8fceb

Please sign in to comment.