Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
19924: drivers/pcf857x: Move compile time check to compilation unit r=maribu a=maribu

### Contribution description

This allows including the header without using the module. Obviously, calls to the functions provided by the header won't like without using the module. But including the header can still be useful for e.g.:

    if (IS_USED(MODULE_PCF857x)) {
        /* make use of the module */
    }

In the above example all calls to pcf857x functions would be optimized out when the module is not used, full compile checks happen in either case.

### Testing procedure

- binaries should not change
- including the pcf857x header should work without having selected one of the pcf857x variants, if the driver is not actually used
    - when calling any of the functions provided, linking should fail
    - when using the `pcf857x` module without any variant, compiling should still fail with a message indicating that (at least) one of the pcf857x needs to be selected

### Issues/PRs references

None

19925: cpu/sam3: assert valid freq in timer_init() r=maribu a=maribu

### Contribution description

The API of timer_init() expects callers to know what frequencies are supported and only use valid frequencies. So let's add an `assert()` to aid debugging if the app uses an invalid.

### Testing procedure

- any valid application should compile and work as before
- an application using an unsupported timer frequency should trigger an `assert()`, rather than letting the timer silently run at a (possibly widely) different frequency

### Issues/PRs references

None

Co-authored-by: Marian Buschsieweke <[email protected]>
  • Loading branch information
bors[bot] and maribu authored Sep 15, 2023
3 parents 7336d9c + d0fccdb + 63caa45 commit 9609a49
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion cpu/sam3/periph/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ int timer_init(tim_t tim, uint32_t freq, timer_cb_t cb, void *arg)
* channel 1 toggles this line on each timer tick, the actual frequency
* driving channel 0 is f_ch2 / 2 --> f_ch0/1 = (MCK / 2) / 2 / freq.
*/
dev(tim)->TC_CHANNEL[1].TC_RC = (CLOCK_CORECLOCK / 4) / freq;
uint32_t tc_rc = (CLOCK_CORECLOCK / 4) / freq;
/* the API expects apps to know in advance which frequencies are possible
* and only configure with supported frequencies. So aid debugging with
* an assert */
assert(tc_rc * freq == CLOCK_CORECLOCK / 4);
dev(tim)->TC_CHANNEL[1].TC_RC = tc_rc;

/* start channel 1 */
dev(tim)->TC_CHANNEL[1].TC_CCR = (TC_CCR_CLKEN | TC_CCR_SWTRG);
Expand Down
4 changes: 0 additions & 4 deletions drivers/include/pcf857x.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ extern "C"
#include "event.h"
#endif /* MODULE_PCF857X_IRQ */

#if !IS_USED(MODULE_PCF8574) && !IS_USED(MODULE_PCF8574A) && !IS_USED(MODULE_PCF8575)
#error "Please provide a list of pcf857x variants used by the application (pcf8574, pcf8574a or pcf8575)"
#endif

/**
* @name PCF857X I2C slave addresses
*
Expand Down
4 changes: 4 additions & 0 deletions drivers/pcf857x/pcf857x.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@

#endif /* ENABLE_DEBUG */

#if !IS_USED(MODULE_PCF8574) && !IS_USED(MODULE_PCF8574A) && !IS_USED(MODULE_PCF8575)
#error "Please provide a list of pcf857x variants used by the application (pcf8574, pcf8574a or pcf8575)"
#endif

#if IS_USED(MODULE_PCF857X_IRQ_LOW)
#define PCF857X_EVENT_PRIO EVENT_PRIO_LOWEST
#elif IS_USED(MODULE_PCF857X_IRQ_MEDIUM)
Expand Down

0 comments on commit 9609a49

Please sign in to comment.