32
32
#include <nrf_pwm.h>
33
33
34
34
/* Mynewt Nordic driver */
35
- #include "pwm_nrf52/pwm_nrf52 .h"
35
+ #include "pwm_nrf5x/pwm_nrf5x .h"
36
36
37
- /* Max number on PWM instances on existing nRF52xxx MCUs */
37
+ /* Max number on PWM instances on existing nRF5x MCUs */
38
38
#if MYNEWT_VAL (BSP_NRF54 )
39
- #define NRF52_PWM_MAX_INSTANCES 3
39
+ #define NRF_PWM_MAX_INSTANCES 3
40
40
#else
41
- #define NRF52_PWM_MAX_INSTANCES 4
41
+ #define NRF_PWM_MAX_INSTANCES 4
42
42
#endif
43
43
44
44
#if MYNEWT_VAL (BSP_NRF54 )
58
58
#define PWM_3_ID 3
59
59
#endif
60
60
61
- struct nrf52_pwm_dev_global {
61
+ struct nrf5x_pwm_dev_global {
62
62
bool in_use ;
63
63
bool playing ;
64
64
nrfx_pwm_t drv_instance ;
@@ -73,7 +73,7 @@ struct nrf52_pwm_dev_global {
73
73
void * seq_end_data ;
74
74
};
75
75
76
- static struct nrf52_pwm_dev_global instances [] =
76
+ static struct nrf5x_pwm_dev_global instances [] =
77
77
{
78
78
#if MYNEWT_VAL (PWM_0 )
79
79
[0 ].in_use = false,
@@ -307,7 +307,7 @@ cleanup_instance(int inst_id)
307
307
}
308
308
309
309
/**
310
- * Open the NRF52 PWM device
310
+ * Open the NRF5x PWM device
311
311
*
312
312
* This function locks the device for access from other tasks.
313
313
*
@@ -322,7 +322,7 @@ cleanup_instance(int inst_id)
322
322
* @return 0 on success, non-zero error code on failure.
323
323
*/
324
324
static int
325
- nrf52_pwm_open (struct os_dev * odev , uint32_t wait , void * arg )
325
+ nrf5x_pwm_open (struct os_dev * odev , uint32_t wait , void * arg )
326
326
{
327
327
struct pwm_dev * dev ;
328
328
int stat = 0 ;
@@ -359,7 +359,7 @@ nrf52_pwm_open(struct os_dev *odev, uint32_t wait, void *arg)
359
359
}
360
360
361
361
/**
362
- * Close the NRF52 PWM device.
362
+ * Close the NRF5x PWM device.
363
363
*
364
364
* This function unlocks the device.
365
365
*
@@ -368,7 +368,7 @@ nrf52_pwm_open(struct os_dev *odev, uint32_t wait, void *arg)
368
368
* @return 0 on success, non-zero error code on failure.
369
369
*/
370
370
static int
371
- nrf52_pwm_close (struct os_dev * odev )
371
+ nrf5x_pwm_close (struct os_dev * odev )
372
372
{
373
373
struct pwm_dev * dev ;
374
374
int inst_id ;
@@ -397,7 +397,7 @@ nrf52_pwm_close(struct os_dev *odev)
397
397
* Play using current configuration.
398
398
*/
399
399
static void
400
- play_current_config (struct nrf52_pwm_dev_global * instance )
400
+ play_current_config (struct nrf5x_pwm_dev_global * instance )
401
401
{
402
402
nrf_pwm_sequence_t const seq =
403
403
{
@@ -423,10 +423,10 @@ play_current_config(struct nrf52_pwm_dev_global *instance)
423
423
* @return 0 on success, non-zero error code on failure.
424
424
*/
425
425
int
426
- nrf52_pwm_configure_device (struct pwm_dev * dev , struct pwm_dev_cfg * cfg )
426
+ nrf5x_pwm_configure_device (struct pwm_dev * dev , struct pwm_dev_cfg * cfg )
427
427
{
428
428
int inst_id = dev -> pwm_instance_id ;
429
- struct nrf52_pwm_dev_global * instance = & instances [inst_id ];
429
+ struct nrf5x_pwm_dev_global * instance = & instances [inst_id ];
430
430
431
431
instance -> n_cycles = (cfg -> n_cycles ) ? cfg -> n_cycles : 1 ;
432
432
@@ -474,12 +474,12 @@ nrf52_pwm_configure_device(struct pwm_dev *dev, struct pwm_dev_cfg *cfg)
474
474
* @return 0 on success, non-zero error code on failure.
475
475
*/
476
476
static int
477
- nrf52_pwm_configure_channel (struct pwm_dev * dev ,
478
- uint8_t cnum ,
479
- struct pwm_chan_cfg * cfg )
477
+ nrf5x_pwm_configure_channel (struct pwm_dev * dev ,
478
+ uint8_t cnum ,
479
+ struct pwm_chan_cfg * cfg )
480
480
{
481
481
int inst_id = dev -> pwm_instance_id ;
482
- struct nrf52_pwm_dev_global * instance = & instances [inst_id ];
482
+ struct nrf5x_pwm_dev_global * instance = & instances [inst_id ];
483
483
nrfx_pwm_config_t * config = & instance -> config ;
484
484
485
485
if (!instance -> in_use ) {
@@ -515,7 +515,7 @@ nrf52_pwm_configure_channel(struct pwm_dev *dev,
515
515
* @return 0 on success, non-zero error code on failure.
516
516
*/
517
517
static int
518
- nrf52_pwm_set_duty_cycle (struct pwm_dev * dev , uint8_t cnum , uint16_t fraction )
518
+ nrf5x_pwm_set_duty_cycle (struct pwm_dev * dev , uint8_t cnum , uint16_t fraction )
519
519
{
520
520
int inst_id = dev -> pwm_instance_id ;
521
521
nrfx_pwm_config_t * config ;
@@ -547,10 +547,10 @@ nrf52_pwm_set_duty_cycle(struct pwm_dev *dev, uint8_t cnum, uint16_t fraction)
547
547
* @return 0 on success, non-zero error code on failure.
548
548
*/
549
549
int
550
- nrf52_pwm_enable (struct pwm_dev * dev )
550
+ nrf5x_pwm_enable (struct pwm_dev * dev )
551
551
{
552
552
int inst_id = dev -> pwm_instance_id ;
553
- struct nrf52_pwm_dev_global * instance = & instances [inst_id ];
553
+ struct nrf5x_pwm_dev_global * instance = & instances [inst_id ];
554
554
555
555
nrfx_pwm_init (& instance -> drv_instance ,
556
556
& instance -> config ,
@@ -571,7 +571,7 @@ nrf52_pwm_enable(struct pwm_dev *dev)
571
571
* @return true if enabled, false if not.
572
572
*/
573
573
static bool
574
- nrf52_pwm_is_enabled (struct pwm_dev * dev )
574
+ nrf5x_pwm_is_enabled (struct pwm_dev * dev )
575
575
{
576
576
return (instances [dev -> pwm_instance_id ].playing );
577
577
}
@@ -584,7 +584,7 @@ nrf52_pwm_is_enabled(struct pwm_dev *dev)
584
584
* @return 0 on success, non-zero error code on failure.
585
585
*/
586
586
static int
587
- nrf52_pwm_disable (struct pwm_dev * dev )
587
+ nrf5x_pwm_disable (struct pwm_dev * dev )
588
588
{
589
589
int inst_id = dev -> pwm_instance_id ;
590
590
if (!instances [inst_id ].in_use ) {
@@ -613,7 +613,7 @@ nrf52_pwm_disable(struct pwm_dev *dev)
613
613
* @return A value is in Hz on success, negative error code on failure.
614
614
*/
615
615
static int
616
- nrf52_pwm_set_frequency (struct pwm_dev * dev , uint32_t freq_hz )
616
+ nrf5x_pwm_set_frequency (struct pwm_dev * dev , uint32_t freq_hz )
617
617
{
618
618
int inst_id = dev -> pwm_instance_id ;
619
619
if (!instances [inst_id ].in_use ) {
@@ -676,7 +676,7 @@ nrf52_pwm_set_frequency(struct pwm_dev *dev, uint32_t freq_hz)
676
676
* @return value is in Hz on success, error code on failure.
677
677
*/
678
678
static int
679
- nrf52_pwm_get_clock_freq (struct pwm_dev * dev )
679
+ nrf5x_pwm_get_clock_freq (struct pwm_dev * dev )
680
680
{
681
681
int inst_id = dev -> pwm_instance_id ;
682
682
if (!instances [inst_id ].in_use ) {
@@ -713,7 +713,7 @@ nrf52_pwm_get_clock_freq(struct pwm_dev *dev)
713
713
* @return value in cycles on success, negative error code on failure.
714
714
*/
715
715
int
716
- nrf52_pwm_get_top_value (struct pwm_dev * dev )
716
+ nrf5x_pwm_get_top_value (struct pwm_dev * dev )
717
717
{
718
718
int inst_id = dev -> pwm_instance_id ;
719
719
if (!instances [inst_id ].in_use ) {
@@ -731,7 +731,7 @@ nrf52_pwm_get_top_value(struct pwm_dev *dev)
731
731
* @return The value in bits on success, negative error code on failure.
732
732
*/
733
733
static int
734
- nrf52_pwm_get_resolution_bits (struct pwm_dev * dev )
734
+ nrf5x_pwm_get_resolution_bits (struct pwm_dev * dev )
735
735
{
736
736
int inst_id = dev -> pwm_instance_id ;
737
737
if (!instances [inst_id ].in_use ) {
@@ -825,11 +825,11 @@ pwm_3_irq_handler(void)
825
825
826
826
/**
827
827
* Callback to initialize an adc_dev structure from the os device
828
- * initialization callback. This sets up a nrf52_pwm_device (), so
828
+ * initialization callback. This sets up a nrf5x_pwm_device (), so
829
829
* that subsequent lookups to this device allow us to manipulate it.
830
830
*/
831
831
int
832
- nrf52_pwm_dev_init (struct os_dev * odev , void * arg )
832
+ nrf5x_pwm_dev_init (struct os_dev * odev , void * arg )
833
833
{
834
834
struct pwm_dev * dev ;
835
835
struct pwm_driver_funcs * pwm_funcs ;
@@ -847,29 +847,29 @@ nrf52_pwm_dev_init(struct os_dev *odev, void *arg)
847
847
* - if number is valid instance_id, let's use it directly
848
848
* - otherwise assume it's a valid pointer
849
849
*/
850
- if (POINTER_TO_UINT (arg ) < NRF52_PWM_MAX_INSTANCES ) {
850
+ if (POINTER_TO_UINT (arg ) < NRF_PWM_MAX_INSTANCES ) {
851
851
dev -> pwm_instance_id = POINTER_TO_UINT (arg );
852
852
} else {
853
853
dev -> pwm_instance_id = * ((int * ) arg );
854
- assert (dev -> pwm_instance_id < NRF52_PWM_MAX_INSTANCES );
854
+ assert (dev -> pwm_instance_id < NRF_PWM_MAX_INSTANCES );
855
855
}
856
856
857
857
dev -> pwm_chan_count = NRF_PWM_CHANNEL_COUNT ;
858
858
os_mutex_init (& dev -> pwm_lock );
859
859
860
- OS_DEV_SETHANDLERS (odev , nrf52_pwm_open , nrf52_pwm_close );
860
+ OS_DEV_SETHANDLERS (odev , nrf5x_pwm_open , nrf5x_pwm_close );
861
861
862
862
pwm_funcs = & dev -> pwm_funcs ;
863
- pwm_funcs -> pwm_configure_device = nrf52_pwm_configure_device ;
864
- pwm_funcs -> pwm_configure_channel = nrf52_pwm_configure_channel ;
865
- pwm_funcs -> pwm_set_duty_cycle = nrf52_pwm_set_duty_cycle ;
866
- pwm_funcs -> pwm_enable = nrf52_pwm_enable ;
867
- pwm_funcs -> pwm_is_enabled = nrf52_pwm_is_enabled ;
868
- pwm_funcs -> pwm_set_frequency = nrf52_pwm_set_frequency ;
869
- pwm_funcs -> pwm_get_clock_freq = nrf52_pwm_get_clock_freq ;
870
- pwm_funcs -> pwm_get_top_value = nrf52_pwm_get_top_value ;
871
- pwm_funcs -> pwm_get_resolution_bits = nrf52_pwm_get_resolution_bits ;
872
- pwm_funcs -> pwm_disable = nrf52_pwm_disable ;
863
+ pwm_funcs -> pwm_configure_device = nrf5x_pwm_configure_device ;
864
+ pwm_funcs -> pwm_configure_channel = nrf5x_pwm_configure_channel ;
865
+ pwm_funcs -> pwm_set_duty_cycle = nrf5x_pwm_set_duty_cycle ;
866
+ pwm_funcs -> pwm_enable = nrf5x_pwm_enable ;
867
+ pwm_funcs -> pwm_is_enabled = nrf5x_pwm_is_enabled ;
868
+ pwm_funcs -> pwm_set_frequency = nrf5x_pwm_set_frequency ;
869
+ pwm_funcs -> pwm_get_clock_freq = nrf5x_pwm_get_clock_freq ;
870
+ pwm_funcs -> pwm_get_top_value = nrf5x_pwm_get_top_value ;
871
+ pwm_funcs -> pwm_get_resolution_bits = nrf5x_pwm_get_resolution_bits ;
872
+ pwm_funcs -> pwm_disable = nrf5x_pwm_disable ;
873
873
874
874
switch (dev -> pwm_instance_id ) {
875
875
#if MYNEWT_VAL (PWM_0 )
0 commit comments