|
| 1 | +/**************************************************************************** |
| 2 | + * boards/arm/ra4/arduino-r4-minima/src/ra4m1_pwm.c |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 7 | + * contributor license agreements. See the NOTICE file distributed with |
| 8 | + * this work for additional information regarding copyright ownership. The |
| 9 | + * ASF licenses this file to you under the Apache License, Version 2.0 (the |
| 10 | + * "License"); you may not use this file except in compliance with the |
| 11 | + * License. You may obtain a copy of the License at |
| 12 | + * |
| 13 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | + * |
| 15 | + * Unless required by applicable law or agreed to in writing, software |
| 16 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 18 | + * License for the specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + * |
| 21 | + ****************************************************************************/ |
| 22 | + |
| 23 | +/**************************************************************************** |
| 24 | + * Included Files |
| 25 | + ****************************************************************************/ |
| 26 | + |
| 27 | +#include <nuttx/config.h> |
| 28 | + |
| 29 | +#include <sys/types.h> |
| 30 | +#include <errno.h> |
| 31 | +#include <debug.h> |
| 32 | + |
| 33 | +#include <nuttx/board.h> |
| 34 | +#include <nuttx/timers/pwm.h> |
| 35 | + |
| 36 | +#include <arch/board/board.h> |
| 37 | + |
| 38 | +#include "ra_pwm.h" |
| 39 | + |
| 40 | +/**************************************************************************** |
| 41 | + * Pre-processor Definitions |
| 42 | + ****************************************************************************/ |
| 43 | + |
| 44 | +/* Configuration ************************************************************/ |
| 45 | + |
| 46 | +/* PWM. |
| 47 | + * There are no dedicated PWM output pins available to the user for PWM |
| 48 | + * testing. |
| 49 | + */ |
| 50 | + |
| 51 | +#ifndef CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL |
| 52 | +# if defined(CONFIG_RA4M1_PWM_CHAN0) |
| 53 | +# warning Assuming PWM channel 0 |
| 54 | +# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 0 |
| 55 | +# elif defined(CONFIG_RA4M1_PWM_CHAN1) |
| 56 | +# warning Assuming PWM channel 1 |
| 57 | +# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 1 |
| 58 | +# elif defined(CONFIG_RA4M1_PWM_CHAN2) |
| 59 | +# warning Assuming PWM channel 2 |
| 60 | +# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 2 |
| 61 | +# elif defined(CONFIG_RA4M1_PWM_CHAN3) |
| 62 | +# warning Assuming PWM channel 3 |
| 63 | +# define CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL 3 |
| 64 | +# endif |
| 65 | +#endif |
| 66 | + |
| 67 | +#if defined(CONFIG_PWM) && defined(CONFIG_RA_PWM) |
| 68 | + |
| 69 | +/**************************************************************************** |
| 70 | + * Public Functions |
| 71 | + ****************************************************************************/ |
| 72 | + |
| 73 | +/**************************************************************************** |
| 74 | + * Name: ra4m1_pwm_setup |
| 75 | + * |
| 76 | + * Description: |
| 77 | + * Initialize PWM and register the PWM device. |
| 78 | + * |
| 79 | + ****************************************************************************/ |
| 80 | + |
| 81 | +int ra4m1_pwm_setup(void) |
| 82 | +{ |
| 83 | + static bool initialized = false; |
| 84 | + struct pwm_lowerhalf_s *pwm; |
| 85 | + int ret; |
| 86 | + |
| 87 | + /* Have we already initialized? */ |
| 88 | + |
| 89 | + if (!initialized) |
| 90 | + { |
| 91 | + /* Call ra_pwminitialize() to get an instance of the PWM interface */ |
| 92 | + |
| 93 | + pwm = ra_pwminitialize(CONFIG_ARDUINO_R4_MINIMA_PWM_CHANNEL); |
| 94 | + if (!pwm) |
| 95 | + { |
| 96 | + _err("ERROR: Failed to get the RA4M1 PWM lower half\n"); |
| 97 | + return -ENODEV; |
| 98 | + } |
| 99 | + |
| 100 | + /* Register the PWM driver at "/dev/pwm0" */ |
| 101 | + |
| 102 | + ret = pwm_register("/dev/pwm0", pwm); |
| 103 | + if (ret < 0) |
| 104 | + { |
| 105 | + aerr("ERROR: pwm_register failed: %d\n", ret); |
| 106 | + return ret; |
| 107 | + } |
| 108 | + |
| 109 | + /* Now we are initialized */ |
| 110 | + |
| 111 | + initialized = true; |
| 112 | + } |
| 113 | + |
| 114 | + return OK; |
| 115 | +} |
| 116 | + |
| 117 | +#endif /* CONFIG_PWM */ |
0 commit comments