15
15
*/
16
16
#include "mbed_assert.h"
17
17
#include "pwmout_api.h"
18
- #include "cmsis.h"
19
18
#include "pinmap.h"
20
19
#include "PeripheralPins.h"
21
20
22
- #include <ti/devices/cc32xx/inc/hw_apps_config.h>
23
- #include <ti/devices/cc32xx/inc/hw_ocp_shared.h>
24
- #include <ti/devices/cc32xx/inc/hw_types.h>
25
- #include <ti/devices/cc32xx/inc/hw_timer.h>
26
- #include <ti/devices/cc32xx/inc/hw_memmap.h>
27
- #include <ti/devices/cc32xx/driverlib/rom.h>
28
- #include <ti/devices/cc32xx/driverlib/rom_map.h>
29
- #include <ti/devices/cc32xx/driverlib/gpio.h>
30
- #include <ti/devices/cc32xx/driverlib/pin.h>
31
- #include <ti/devices/cc32xx/driverlib/ti_timer.h>
32
-
33
- static const uint32_t timerBaseAddresses [4 ] = {
34
- CC3220SF_TIMERA0_BASE ,
35
- CC3220SF_TIMERA1_BASE ,
36
- CC3220SF_TIMERA2_BASE ,
37
- CC3220SF_TIMERA3_BASE ,
38
- };
39
-
40
- static const uint32_t timerHalves [2 ] = {
41
- TIMER_A ,
42
- TIMER_B ,
43
- };
44
-
45
- /*static const uint32_t gpioBaseAddresses[4] = {
46
- CC3220SF_GPIOA0_BASE,
47
- CC3220SF_GPIOA1_BASE,
48
- CC3220SF_GPIOA2_BASE,
49
- CC3220SF_GPIOA3_BASE,
50
- };*/
51
-
52
- /*static const uint32_t gpioPinIndexes[8] = {
53
- GPIO_PIN_0,
54
- GPIO_PIN_1,
55
- GPIO_PIN_2,
56
- GPIO_PIN_3,
57
- GPIO_PIN_4,
58
- GPIO_PIN_5,
59
- GPIO_PIN_6,
60
- GPIO_PIN_7,
61
- };*/
62
-
63
- #define PinConfigTimerPort (config ) (((config) >> 28) & 0xF)
64
- #define PinConfigTimerHalf (config ) (((config) >> 24) & 0xF)
65
- #define PinConfigGPIOPort (config ) (((config) >> 20) & 0xF)
66
- #define PinConfigGPIOPinIndex (config ) (((config) >> 16) & 0xF)
67
- #define PinConfigPinMode (config ) (((config) >> 8) & 0xF)
68
- #define PinConfigPin (config ) (((config) >> 0) & 0x3F)
69
-
70
- #define PWMTimerCC32XX_T0A (0x00 << 24)
71
- #define PWMTimerCC32XX_T0B (0x01 << 24)
72
- #define PWMTimerCC32XX_T1A (0x10 << 24)
73
- #define PWMTimerCC32XX_T1B (0x11 << 24)
74
- #define PWMTimerCC32XX_T2A (0x20 << 24)
75
- #define PWMTimerCC32XX_T2B (0x21 << 24)
76
- #define PWMTimerCC32XX_T3A (0x30 << 24)
77
- #define PWMTimerCC32XX_T3B (0x31 << 24)
78
-
79
- #define PWMTimerCC32XX_GPIO9 (0x11 << 16)
80
- #define PWMTimerCC32XX_GPIO10 (0x12 << 16)
81
- #define PWMTimerCC32XX_GPIO11 (0x13 << 16)
82
- #define PWMTimerCC32XX_GPIO24 (0x30 << 16)
83
- #define PWMTimerCC32XX_GPIO25 (0x31 << 16)
84
-
85
- #define PWMTimerCC32XX_GPIONONE (0xFF << 16)
86
-
87
- #define PWMTimerCC32XX_PIN_01 (PWMTimerCC32XX_T3A | PWMTimerCC32XX_GPIO10 | 0x0300)
88
- #define PWMTimerCC32XX_PIN_02 (PWMTimerCC32XX_T3B | PWMTimerCC32XX_GPIO11 | 0x0301)
89
- #define PWMTimerCC32XX_PIN_17 (PWMTimerCC32XX_T0A | PWMTimerCC32XX_GPIO24 | 0x0510)
90
- #define PWMTimerCC32XX_PIN_19 (PWMTimerCC32XX_T1B | PWMTimerCC32XX_GPIONONE | 0x0812)
91
- #define PWMTimerCC32XX_PIN_21 (PWMTimerCC32XX_T1A | PWMTimerCC32XX_GPIO25 | 0x0914)
92
- #define PWMTimerCC32XX_PIN_64 (PWMTimerCC32XX_T2B | PWMTimerCC32XX_GPIO9 | 0x033F)
93
-
94
- //static unsigned int pwm_clock_mhz;
21
+ #include <ti/drivers/pwm/PWMTimerCC32XX.h>
22
+ #include <ti/drivers/PWM.h>
23
+ #include <CC3220SF_LAUNCHXL.h>
24
+
25
+ extern const PWM_Config PWM_config [];
95
26
96
27
void pwmout_init (pwmout_t * obj , PinName pin ) {
28
+ PWM_Params pwmParams ;
29
+ int pwmIndex = CC3220SF_LAUNCHXL_PWMCOUNT ;
30
+
31
+ PWM_init ();
32
+
97
33
PWMName pwm = (PWMName )pinmap_peripheral (pin , PinMap_PWM );
98
34
MBED_ASSERT (pwm != (PWMName )NC );
35
+
99
36
obj -> pwm = pwm ;
100
37
101
38
switch (pin ) {
102
- case PIN_01 : obj -> pwmPin = PWMTimerCC32XX_PIN_01 ; break ;
103
- case PIN_02 : obj -> pwmPin = PWMTimerCC32XX_PIN_02 ; break ;
104
- case PIN_17 : obj -> pwmPin = PWMTimerCC32XX_PIN_17 ; break ;
105
- case PIN_19 : obj -> pwmPin = PWMTimerCC32XX_PIN_19 ; break ;
106
- case PIN_21 : obj -> pwmPin = PWMTimerCC32XX_PIN_21 ; break ;
107
- case PIN_64 : obj -> pwmPin = PWMTimerCC32XX_PIN_64 ; break ;
108
- default : break ;
109
- }
39
+ case PIN_01 :
40
+ pwmIndex = CC3220SF_LAUNCHXL_PWM6 ;
41
+ break ;
110
42
111
- uint32_t timerBaseAddr = timerBaseAddresses [PinConfigTimerPort (obj -> pwmPin )];
112
- uint16_t halfTimer = timerHalves [PinConfigTimerHalf (obj -> pwmPin )];
113
-
114
- MAP_TimerDisable (timerBaseAddr , halfTimer );
115
-
116
- /*
117
- * The CC32XX SDK TimerConfigure API halts both timers when it is
118
- * used to configure a single half timer. The code below performs
119
- * the register operations necessary to configure each half timer
120
- * individually.
121
- */
122
- /* Enable CCP to IO path */
123
- HWREG (APPS_CONFIG_BASE + APPS_CONFIG_O_GPT_TRIG_SEL ) = 0xFF ;
124
-
125
- /* Split the timer and configure it as a PWM */
126
- uint32_t timerConfigVal = ((halfTimer & (TIMER_CFG_A_PWM | TIMER_CFG_B_PWM )) |
127
- TIMER_CFG_SPLIT_PAIR );
128
- HWREG (timerBaseAddr + TIMER_O_CFG ) |= (timerConfigVal >> 24 );
129
- if (halfTimer & TIMER_A ) {
130
- HWREG (timerBaseAddr + TIMER_O_TAMR ) = timerConfigVal & 255 ;
131
- }
132
- else {
133
- HWREG (timerBaseAddr + TIMER_O_TBMR ) = (timerConfigVal >> 8 ) & 255 ;
43
+ case PIN_02 :
44
+ pwmIndex = CC3220SF_LAUNCHXL_PWM7 ;
45
+ break ;
46
+
47
+ case PIN_17 :
48
+ pwmIndex = CC3220SF_LAUNCHXL_PWM0 ;
49
+ break ;
50
+
51
+ case PIN_19 :
52
+ pwmIndex = CC3220SF_LAUNCHXL_PWM3 ;
53
+ break ;
54
+
55
+ case PIN_21 :
56
+ pwmIndex = CC3220SF_LAUNCHXL_PWM2 ;
57
+ break ;
58
+
59
+ case PIN_64 :
60
+ pwmIndex = CC3220SF_LAUNCHXL_PWM5 ;
61
+ break ;
62
+
63
+ default :
64
+ while (1 );
134
65
}
135
66
136
- /* Set the peripheral output to active-high */
137
- MAP_TimerControlLevel (timerBaseAddr , halfTimer , true);
67
+ obj -> handle = (void * )& PWM_config [pwmIndex ];
68
+
69
+ // Initialize the PWM parameters
70
+ PWM_Params_init (& pwmParams );
138
71
139
- uint16_t mode = PinConfigPinMode (obj -> pwmPin );
72
+ obj -> duty_percent = PWM_DEFAULT_DUTY_PERCENT ;
73
+ obj -> period_us = PWM_DEFAULT_PERIOD_US ;
140
74
141
- /* Start the timer & set pinmux to PWM mode */
142
- MAP_TimerEnable (timerBaseAddr , halfTimer );
143
- MAP_PinTypeTimer ((unsigned long )pin , (unsigned long )mode );
75
+ if (PWM_open (pwmIndex , & pwmParams ))
76
+ {
77
+ PWM_start ((PWM_Handle )obj -> handle );
78
+ }
79
+ else
80
+ {
81
+ while (1 );
82
+ }
144
83
}
145
84
146
85
void pwmout_free (pwmout_t * obj ) {
147
- // [TODO]
86
+ PWM_stop ((PWM_Handle )obj -> handle );
87
+ PWM_close ((PWM_Handle )obj -> handle );
148
88
}
149
89
150
90
void pwmout_write (pwmout_t * obj , float value ) {
151
-
91
+ PWM_setDuty ((PWM_Handle )obj -> handle , value * 100 );
92
+ obj -> duty_percent = value ;
152
93
}
153
94
154
95
float pwmout_read (pwmout_t * obj ) {
155
- return 0 ;
96
+ return ( obj -> duty_percent ) ;
156
97
}
157
98
158
99
void pwmout_period (pwmout_t * obj , float seconds ) {
159
- pwmout_period_us (obj , seconds * 1000000.0f );
100
+ pwmout_period_us (obj , seconds * 1000 * 1000 );
160
101
}
161
102
162
103
void pwmout_period_ms (pwmout_t * obj , int ms ) {
@@ -165,7 +106,8 @@ void pwmout_period_ms(pwmout_t* obj, int ms) {
165
106
166
107
// Set the PWM period, keeping the duty cycle the same.
167
108
void pwmout_period_us (pwmout_t * obj , int us ) {
168
-
109
+ PWM_setPeriod ((PWM_Handle )obj -> handle , us );
110
+ obj -> period_us = us ;
169
111
}
170
112
171
113
void pwmout_pulsewidth (pwmout_t * obj , float seconds ) {
@@ -177,7 +119,11 @@ void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
177
119
}
178
120
179
121
void pwmout_pulsewidth_us (pwmout_t * obj , int us ) {
180
-
122
+ if (obj -> period_us )
123
+ {
124
+ float value = (float )us / (float )obj -> period_us ;
125
+ pwmout_write (obj , value );
126
+ }
181
127
}
182
128
183
129
const PinMap * pwmout_pinmap ()
0 commit comments