Skip to content

Commit 3507a6a

Browse files
committed
hw/drivers: Refactor nrf5x PWM driver
This renames the driver from pwm_nrf52 to pwm_nrf5x as it is used with other supported nrf5x devices
1 parent e0ac5ee commit 3507a6a

File tree

9 files changed

+72
-74
lines changed

9 files changed

+72
-74
lines changed

hw/drivers/pwm/pwm_nrf52/include/pwm_nrf52/pwm_nrf52.h renamed to hw/drivers/pwm/pwm_nrf5x/include/pwm_nrf5x/pwm_nrf5x.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* under the License.
1818
*/
1919

20-
#ifndef __PWM_NRF52_H__
21-
#define __PWM_NRF52_H__
20+
#ifndef __PWM_NRF5X_H__
21+
#define __PWM_NRF5X_H__
2222

2323
#include <pwm/pwm.h>
2424

@@ -28,10 +28,10 @@
2828
extern "C" {
2929
#endif
3030

31-
int nrf52_pwm_dev_init(struct os_dev *, void *);
31+
int nrf5x_pwm_dev_init(struct os_dev *odev, void *arg);
3232

3333
#ifdef __cplusplus
3434
}
3535
#endif
3636

37-
#endif /* __PWM_NRF52_H__ */
37+
#endif /* __PWM_NRF5X_H__ */

hw/drivers/pwm/pwm_nrf52/pkg.yml renamed to hw/drivers/pwm/pwm_nrf5x/pkg.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
# under the License.
1818
#
1919

20-
pkg.name: hw/drivers/pwm/pwm_nrf52
21-
pkg.description: PWM driver for the NRF52
20+
pkg.name: hw/drivers/pwm/pwm_nrf5x
21+
pkg.description: PWM driver for the NRF5x devices
2222
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
2323
pkg.homepage: "http://mynewt.apache.org/"
2424
pkg.keywords:

hw/drivers/pwm/pwm_nrf52/src/pwm_nrf52.c renamed to hw/drivers/pwm/pwm_nrf5x/src/pwm_nrf5x.c

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
3232
#include <nrf_pwm.h>
3333

3434
/* Mynewt Nordic driver */
35-
#include "pwm_nrf52/pwm_nrf52.h"
35+
#include "pwm_nrf5x/pwm_nrf5x.h"
3636

37-
/* Max number on PWM instances on existing nRF52xxx MCUs */
37+
/* Max number on PWM instances on existing nRF5x MCUs */
3838
#if MYNEWT_VAL(BSP_NRF54)
39-
#define NRF52_PWM_MAX_INSTANCES 3
39+
#define NRF_PWM_MAX_INSTANCES 3
4040
#else
41-
#define NRF52_PWM_MAX_INSTANCES 4
41+
#define NRF_PWM_MAX_INSTANCES 4
4242
#endif
4343

4444
#if MYNEWT_VAL(BSP_NRF54)
@@ -58,7 +58,7 @@
5858
#define PWM_3_ID 3
5959
#endif
6060

61-
struct nrf52_pwm_dev_global {
61+
struct nrf5x_pwm_dev_global {
6262
bool in_use;
6363
bool playing;
6464
nrfx_pwm_t drv_instance;
@@ -73,7 +73,7 @@ struct nrf52_pwm_dev_global {
7373
void* seq_end_data;
7474
};
7575

76-
static struct nrf52_pwm_dev_global instances[] =
76+
static struct nrf5x_pwm_dev_global instances[] =
7777
{
7878
#if MYNEWT_VAL(PWM_0)
7979
[0].in_use = false,
@@ -307,7 +307,7 @@ cleanup_instance(int inst_id)
307307
}
308308

309309
/**
310-
* Open the NRF52 PWM device
310+
* Open the NRF5x PWM device
311311
*
312312
* This function locks the device for access from other tasks.
313313
*
@@ -322,7 +322,7 @@ cleanup_instance(int inst_id)
322322
* @return 0 on success, non-zero error code on failure.
323323
*/
324324
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)
326326
{
327327
struct pwm_dev *dev;
328328
int stat = 0;
@@ -359,7 +359,7 @@ nrf52_pwm_open(struct os_dev *odev, uint32_t wait, void *arg)
359359
}
360360

361361
/**
362-
* Close the NRF52 PWM device.
362+
* Close the NRF5x PWM device.
363363
*
364364
* This function unlocks the device.
365365
*
@@ -368,7 +368,7 @@ nrf52_pwm_open(struct os_dev *odev, uint32_t wait, void *arg)
368368
* @return 0 on success, non-zero error code on failure.
369369
*/
370370
static int
371-
nrf52_pwm_close(struct os_dev *odev)
371+
nrf5x_pwm_close(struct os_dev *odev)
372372
{
373373
struct pwm_dev *dev;
374374
int inst_id;
@@ -397,7 +397,7 @@ nrf52_pwm_close(struct os_dev *odev)
397397
* Play using current configuration.
398398
*/
399399
static void
400-
play_current_config(struct nrf52_pwm_dev_global *instance)
400+
play_current_config(struct nrf5x_pwm_dev_global *instance)
401401
{
402402
nrf_pwm_sequence_t const seq =
403403
{
@@ -423,10 +423,10 @@ play_current_config(struct nrf52_pwm_dev_global *instance)
423423
* @return 0 on success, non-zero error code on failure.
424424
*/
425425
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)
427427
{
428428
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];
430430

431431
instance->n_cycles = (cfg->n_cycles) ? cfg->n_cycles : 1;
432432

@@ -474,12 +474,12 @@ nrf52_pwm_configure_device(struct pwm_dev *dev, struct pwm_dev_cfg *cfg)
474474
* @return 0 on success, non-zero error code on failure.
475475
*/
476476
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)
480480
{
481481
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];
483483
nrfx_pwm_config_t *config = &instance->config;
484484

485485
if (!instance->in_use) {
@@ -515,7 +515,7 @@ nrf52_pwm_configure_channel(struct pwm_dev *dev,
515515
* @return 0 on success, non-zero error code on failure.
516516
*/
517517
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)
519519
{
520520
int inst_id = dev->pwm_instance_id;
521521
nrfx_pwm_config_t *config;
@@ -547,10 +547,10 @@ nrf52_pwm_set_duty_cycle(struct pwm_dev *dev, uint8_t cnum, uint16_t fraction)
547547
* @return 0 on success, non-zero error code on failure.
548548
*/
549549
int
550-
nrf52_pwm_enable(struct pwm_dev *dev)
550+
nrf5x_pwm_enable(struct pwm_dev *dev)
551551
{
552552
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];
554554

555555
nrfx_pwm_init(&instance->drv_instance,
556556
&instance->config,
@@ -571,7 +571,7 @@ nrf52_pwm_enable(struct pwm_dev *dev)
571571
* @return true if enabled, false if not.
572572
*/
573573
static bool
574-
nrf52_pwm_is_enabled(struct pwm_dev *dev)
574+
nrf5x_pwm_is_enabled(struct pwm_dev *dev)
575575
{
576576
return (instances[dev->pwm_instance_id].playing);
577577
}
@@ -584,7 +584,7 @@ nrf52_pwm_is_enabled(struct pwm_dev *dev)
584584
* @return 0 on success, non-zero error code on failure.
585585
*/
586586
static int
587-
nrf52_pwm_disable(struct pwm_dev *dev)
587+
nrf5x_pwm_disable(struct pwm_dev *dev)
588588
{
589589
int inst_id = dev->pwm_instance_id;
590590
if (!instances[inst_id].in_use) {
@@ -613,7 +613,7 @@ nrf52_pwm_disable(struct pwm_dev *dev)
613613
* @return A value is in Hz on success, negative error code on failure.
614614
*/
615615
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)
617617
{
618618
int inst_id = dev->pwm_instance_id;
619619
if (!instances[inst_id].in_use) {
@@ -676,7 +676,7 @@ nrf52_pwm_set_frequency(struct pwm_dev *dev, uint32_t freq_hz)
676676
* @return value is in Hz on success, error code on failure.
677677
*/
678678
static int
679-
nrf52_pwm_get_clock_freq(struct pwm_dev *dev)
679+
nrf5x_pwm_get_clock_freq(struct pwm_dev *dev)
680680
{
681681
int inst_id = dev->pwm_instance_id;
682682
if (!instances[inst_id].in_use) {
@@ -713,7 +713,7 @@ nrf52_pwm_get_clock_freq(struct pwm_dev *dev)
713713
* @return value in cycles on success, negative error code on failure.
714714
*/
715715
int
716-
nrf52_pwm_get_top_value(struct pwm_dev *dev)
716+
nrf5x_pwm_get_top_value(struct pwm_dev *dev)
717717
{
718718
int inst_id = dev->pwm_instance_id;
719719
if (!instances[inst_id].in_use) {
@@ -731,7 +731,7 @@ nrf52_pwm_get_top_value(struct pwm_dev *dev)
731731
* @return The value in bits on success, negative error code on failure.
732732
*/
733733
static int
734-
nrf52_pwm_get_resolution_bits(struct pwm_dev *dev)
734+
nrf5x_pwm_get_resolution_bits(struct pwm_dev *dev)
735735
{
736736
int inst_id = dev->pwm_instance_id;
737737
if (!instances[inst_id].in_use) {
@@ -825,11 +825,11 @@ pwm_3_irq_handler(void)
825825

826826
/**
827827
* 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
829829
* that subsequent lookups to this device allow us to manipulate it.
830830
*/
831831
int
832-
nrf52_pwm_dev_init(struct os_dev *odev, void *arg)
832+
nrf5x_pwm_dev_init(struct os_dev *odev, void *arg)
833833
{
834834
struct pwm_dev *dev;
835835
struct pwm_driver_funcs *pwm_funcs;
@@ -847,29 +847,29 @@ nrf52_pwm_dev_init(struct os_dev *odev, void *arg)
847847
* - if number is valid instance_id, let's use it directly
848848
* - otherwise assume it's a valid pointer
849849
*/
850-
if (POINTER_TO_UINT(arg) < NRF52_PWM_MAX_INSTANCES) {
850+
if (POINTER_TO_UINT(arg) < NRF_PWM_MAX_INSTANCES) {
851851
dev->pwm_instance_id = POINTER_TO_UINT(arg);
852852
} else {
853853
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);
855855
}
856856

857857
dev->pwm_chan_count = NRF_PWM_CHANNEL_COUNT;
858858
os_mutex_init(&dev->pwm_lock);
859859

860-
OS_DEV_SETHANDLERS(odev, nrf52_pwm_open, nrf52_pwm_close);
860+
OS_DEV_SETHANDLERS(odev, nrf5x_pwm_open, nrf5x_pwm_close);
861861

862862
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;
873873

874874
switch (dev->pwm_instance_id) {
875875
#if MYNEWT_VAL(PWM_0)

hw/mcu/nordic/nrf52xxx/pkg.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ pkg.deps.ADC_0:
6666
- "@apache-mynewt-core/hw/drivers/adc/adc_nrf52"
6767

6868
pkg.deps.PWM_0:
69-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
69+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
7070

7171
pkg.deps.PWM_1:
72-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
72+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
7373

7474
pkg.deps.PWM_2:
75-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
75+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
7676

7777
pkg.deps.PWM_3:
78-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
78+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
7979

8080
pkg.deps.TEMP:
8181
- "@apache-mynewt-core/hw/drivers/temp/temp_nrf52"

hw/mcu/nordic/nrf52xxx/src/nrf52_periph.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#endif
4545
#if MYNEWT_VAL(PWM_0) || MYNEWT_VAL(PWM_1) || MYNEWT_VAL(PWM_2) || MYNEWT_VAL(PWM_3)
4646
#include "pwm/pwm.h"
47-
#include "pwm_nrf52/pwm_nrf52.h"
47+
#include "pwm_nrf5x/pwm_nrf5x.h"
4848
#endif
4949
#if MYNEWT_VAL(TRNG)
5050
#include "trng/trng.h"
@@ -307,25 +307,25 @@ nrf52_periph_create_pwm(void)
307307
#if MYNEWT_VAL(PWM_0)
308308
rc = os_dev_create(&os_bsp_pwm0.pwm_os_dev, "pwm0",
309309
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
310-
nrf52_pwm_dev_init, UINT_TO_POINTER(0));
310+
nrf5x_pwm_dev_init, UINT_TO_POINTER(0));
311311
assert(rc == 0);
312312
#endif
313313
#if MYNEWT_VAL(PWM_1)
314314
rc = os_dev_create(&os_bsp_pwm1.pwm_os_dev, "pwm1",
315315
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
316-
nrf52_pwm_dev_init, UINT_TO_POINTER(1));
316+
nrf5x_pwm_dev_init, UINT_TO_POINTER(1));
317317
assert(rc == 0);
318318
#endif
319319
#if MYNEWT_VAL(PWM_2)
320320
rc = os_dev_create(&os_bsp_pwm2.pwm_os_dev, "pwm2",
321321
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
322-
nrf52_pwm_dev_init, UINT_TO_POINTER(2));
322+
nrf5x_pwm_dev_init, UINT_TO_POINTER(2));
323323
assert(rc == 0);
324324
#endif
325325
#if MYNEWT_VAL(PWM_3)
326326
rc = os_dev_create(&os_bsp_pwm3.pwm_os_dev, "pwm3",
327327
OS_DEV_INIT_KERNEL, OS_DEV_INIT_PRIO_DEFAULT,
328-
nrf52_pwm_dev_init, UINT_TO_POINTER(3));
328+
nrf5x_pwm_dev_init, UINT_TO_POINTER(3));
329329
assert(rc == 0);
330330
#endif
331331
}

hw/mcu/nordic/nrf5340/pkg.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,17 @@ pkg.deps.UART_3:
5959
pkg.deps.ADC_0:
6060
- "@apache-mynewt-core/hw/drivers/adc/adc_nrf52"
6161

62-
#nrf52 driver is using nrfx so we can just reuse it
6362
pkg.deps.PWM_0:
64-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
63+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
6564

6665
pkg.deps.PWM_1:
67-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
66+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
6867

6968
pkg.deps.PWM_2:
70-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
69+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
7170

7271
pkg.deps.PWM_3:
73-
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf52"
72+
- "@apache-mynewt-core/hw/drivers/pwm/pwm_nrf5x"
7473

7574
pkg.deps.SPI_0_MASTER:
7675
- "@apache-mynewt-core/hw/bus"

0 commit comments

Comments
 (0)