Skip to content

Commit 0b8fceb

Browse files
kegilbertithinuel
authored andcommitted
Add status code/get call to SAI and children classes
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
1 parent 5f302f1 commit 0b8fceb

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

drivers/SAI.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ SAI::SAI(PinName mclk, PinName bclk, PinName wclk, PinName sd,
3838

3939
init.format = *fmt;
4040

41-
if (sai_init(&_sai, &init) != SAI_RESULT_OK) {
42-
// it failed :o
43-
}
41+
_status = sai_init(&_sai, &init);
4442
}
4543

4644
bool SAI::xfer(uint32_t *value) {
@@ -50,6 +48,10 @@ bool SAI::xfer(uint32_t *value) {
5048
return ret;
5149
}
5250

51+
sai_result_t SAI::status(void) {
52+
return _status;
53+
}
54+
5355
void SAI::lock() {
5456
_mutex.lock();
5557
}

drivers/SAI.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@ class SAI : private NonCopyable<SAI> {
4141
const sai_format_t *fmt = &sai_mode_i2s32, bool is_input = false,
4242
uint32_t master_clock = 0, bool internal_mclk = false);
4343

44+
/** Retreive the object status. Allows the ctor to
45+
* funnel init errors/warnings back up to the application.
46+
*/
47+
virtual sai_result_t status(void);
48+
4449
/** Push a sample to the Fifo & try to read a new sample.
4550
* it may return 0 if no sample was available.
4651
*/
4752
virtual bool xfer(uint32_t *value);
4853

54+
virtual ~SAI() {}
55+
56+
protected:
4957
/** Acquire exclusive access to this SAI bus
5058
*/
5159
virtual void lock(void);
@@ -54,17 +62,14 @@ class SAI : private NonCopyable<SAI> {
5462
*/
5563
virtual void unlock(void);
5664

57-
58-
public:
59-
virtual ~SAI() {}
60-
61-
protected:
65+
////////////////////////////////////////////
6266
sai_t _sai;
6367
PlatformMutex _mutex;
6468
bool _is_input;
69+
sai_result_t _status;
6570
};
6671

67-
class SAITransmitter : private SAI {
72+
class SAITransmitter : public SAI {
6873
public:
6974
SAITransmitter(PinName mclk, PinName bclk, PinName wclk, PinName sd,
7075
const sai_format_t *fmt = &sai_mode_i2s32)
@@ -75,7 +80,7 @@ class SAITransmitter : private SAI {
7580
}
7681
};
7782

78-
class SAIReceiver : private SAI {
83+
class SAIReceiver : public SAI {
7984
public:
8085
SAIReceiver(PinName mclk, PinName bclk, PinName wclk, PinName sd,
8186
const sai_format_t *fmt = &sai_mode_i2s32)

0 commit comments

Comments
 (0)