Skip to content

Commit b2d44a1

Browse files
Finish PWM driver, start getting PWM and ADC working
1 parent f31cd07 commit b2d44a1

File tree

8 files changed

+107
-132
lines changed

8 files changed

+107
-132
lines changed

drivers/source/PwmOut.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -57,74 +57,74 @@ PwmOut::~PwmOut()
5757

5858
void PwmOut::write(float value)
5959
{
60-
core_util_critical_section_enter();
60+
//core_util_critical_section_enter();
6161
pwmout_write(&_pwm, value);
62-
core_util_critical_section_exit();
62+
//core_util_critical_section_exit();
6363
}
6464

6565
float PwmOut::read()
6666
{
67-
core_util_critical_section_enter();
67+
//core_util_critical_section_enter();
6868
float val = pwmout_read(&_pwm);
69-
core_util_critical_section_exit();
69+
//core_util_critical_section_exit();
7070
return val;
7171
}
7272

7373
void PwmOut::period(float seconds)
7474
{
75-
core_util_critical_section_enter();
75+
//core_util_critical_section_enter();
7676
pwmout_period(&_pwm, seconds);
77-
core_util_critical_section_exit();
77+
//core_util_critical_section_exit();
7878
}
7979

8080
void PwmOut::period_ms(int ms)
8181
{
82-
core_util_critical_section_enter();
82+
//core_util_critical_section_enter();
8383
pwmout_period_ms(&_pwm, ms);
84-
core_util_critical_section_exit();
84+
//core_util_critical_section_exit();
8585
}
8686

8787
void PwmOut::period_us(int us)
8888
{
89-
core_util_critical_section_enter();
89+
//core_util_critical_section_enter();
9090
pwmout_period_us(&_pwm, us);
91-
core_util_critical_section_exit();
91+
//core_util_critical_section_exit();
9292
}
9393

9494
int PwmOut::read_period_us()
9595
{
96-
core_util_critical_section_enter();
96+
//core_util_critical_section_enter();
9797
auto val = pwmout_read_period_us(&_pwm);
98-
core_util_critical_section_exit();
98+
//core_util_critical_section_exit();
9999
return val;
100100
}
101101

102102
void PwmOut::pulsewidth(float seconds)
103103
{
104-
core_util_critical_section_enter();
104+
//core_util_critical_section_enter();
105105
pwmout_pulsewidth(&_pwm, seconds);
106-
core_util_critical_section_exit();
106+
//core_util_critical_section_exit();
107107
}
108108

109109
void PwmOut::pulsewidth_ms(int ms)
110110
{
111-
core_util_critical_section_enter();
111+
//core_util_critical_section_enter();
112112
pwmout_pulsewidth_ms(&_pwm, ms);
113-
core_util_critical_section_exit();
113+
//core_util_critical_section_exit();
114114
}
115115

116116
void PwmOut::pulsewidth_us(int us)
117117
{
118-
core_util_critical_section_enter();
118+
//core_util_critical_section_enter();
119119
pwmout_pulsewidth_us(&_pwm, us);
120-
core_util_critical_section_exit();
120+
//core_util_critical_section_exit();
121121
}
122122

123123
int PwmOut::read_pulsewidth_us()
124124
{
125-
core_util_critical_section_enter();
125+
//core_util_critical_section_enter();
126126
auto val = pwmout_read_pulsewidth_us(&_pwm);
127-
core_util_critical_section_exit();
127+
//core_util_critical_section_exit();
128128
return val;
129129
}
130130

@@ -135,24 +135,24 @@ int PwmOut::read_pulsewitdth_us()
135135

136136
void PwmOut::suspend()
137137
{
138-
core_util_critical_section_enter();
138+
//core_util_critical_section_enter();
139139
if (_initialized) {
140140
_duty_cycle = PwmOut::read();
141141
_period_us = PwmOut::read_period_us();
142142
PwmOut::deinit();
143143
}
144-
core_util_critical_section_exit();
144+
//core_util_critical_section_exit();
145145
}
146146

147147
void PwmOut::resume()
148148
{
149-
core_util_critical_section_enter();
149+
//core_util_critical_section_enter();
150150
if (!_initialized) {
151151
PwmOut::init();
152152
PwmOut::period_us(_period_us);
153153
PwmOut::write(_duty_cycle);
154154
}
155-
core_util_critical_section_exit();
155+
//core_util_critical_section_exit();
156156
}
157157

158158
void PwmOut::lock_deep_sleep()
@@ -183,7 +183,7 @@ void PwmOut::_call_pwmout_init(PwmOut *thisPtr)
183183

184184
void PwmOut::init()
185185
{
186-
core_util_critical_section_enter();
186+
//core_util_critical_section_enter();
187187

188188
if (!_initialized) {
189189

@@ -194,20 +194,20 @@ void PwmOut::init()
194194
_initialized = true;
195195
}
196196

197-
core_util_critical_section_exit();
197+
//core_util_critical_section_exit();
198198
}
199199

200200
void PwmOut::deinit()
201201
{
202-
core_util_critical_section_enter();
202+
//core_util_critical_section_enter();
203203

204204
if (_initialized) {
205205
pwmout_free(&_pwm);
206206
unlock_deep_sleep();
207207
_initialized = false;
208208
}
209209

210-
core_util_critical_section_exit();
210+
//core_util_critical_section_exit();
211211
}
212212

213213
} // namespace mbed

hal/include/hal/pwmout_api.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct pwmout_s pwmout_t;
4242
* * ::pwmout_write sets the output duty-cycle in range <0.0f, 1.0f>
4343
* * ::pwmout_read returns the current float-point output duty-cycle in range <0.0f, 1.0f>
4444
* * ::pwmout_period sets the PWM period specified in seconds, keeping the duty cycle the same
45-
* * ::pwmout_period_ms sets the PWM period specified in miliseconds, keeping the duty cycle the same
45+
* * ::pwmout_period_ms sets the PWM period specified in milliseconds, keeping the duty cycle the same
4646
* * ::pwmout_period_us sets the PWM period specified in microseconds, keeping the duty cycle the same
4747
* * ::pwmout_read_period_us reads the PWM period specified in microseconds
4848
* * ::pwmout_pulsewidth sets the PWM pulsewidth specified in seconds, keeping the period the same
@@ -84,7 +84,11 @@ void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap);
8484
*/
8585
void pwmout_init(pwmout_t *obj, PinName pin);
8686

87-
/** Deinitialize the pwmout object
87+
/**
88+
* @brief Deinitialize the pwmout object
89+
*
90+
* After this function is called, the PWM output must stop generating edges.
91+
* The logic level is not specified -- it may be left high, low, or tristated.
8892
*
8993
* @param obj The pwmout object
9094
*/

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/TARGET_SFE_ARTEMIS/PinNames.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ typedef enum
143143
#define QWIIC_SCL I2C_SCL
144144
#define QWIIC_SDA I2C_SDA
145145

146-
// SPI bus
147-
#define SPI_SCLK IO_5
148-
#define SPI_MOSI IO_7
149-
#define SPI_MISO IO_6
150-
151146
#if defined(MBED_CONF_TARGET_STDIO_UART_TX)
152147
#define STDIO_UART_TX MBED_CONF_TARGET_STDIO_UART_TX
153148
#else

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/PeripheralPins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const PinMap PinMap_SPI_SSEL[] = {
271271
// can actually map to one of 6 different PWM module outputs. However, there are as many PWM module
272272
// outputs as there are pins, so we don't need to use this just to give every pin its own PWM output.
273273
// For now, we always use the first possible option (Output Selection 2 in Table 814).
274-
const PinMap PinMap_PWM[] = {
274+
const PinMap PinMap_PWM_OUT[] = {
275275
{IO_12, CTIMER_A0_OUT1, AM_HAL_PIN_12_CTIM0},
276276
{IO_25, CTIMER_A0_OUT2, AM_HAL_PIN_25_CTIM1},
277277
{IO_13, CTIMER_B0_OUT1, AM_HAL_PIN_13_CTIM2},

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/analogin_api.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ uint16_t analogin_read_u16(analogin_t *obj)
153153

154154
float analogin_read(analogin_t *obj)
155155
{
156-
/* Read the raw 12-Bit value from the ADC. */
157-
float analog_in_raw = (float)analogin_read_u16(obj);
156+
/* Read the raw 14-Bit value from the ADC. */
157+
uint16_t analog_in_raw = readAnalogIn(obj);
158+
158159
/* Convert it to a voltage value. */
159160
return (analog_in_raw * ADC_CONVERSION_FACTOR);
160161
}

targets/TARGET_Ambiq_Micro/TARGET_Apollo3/device/objects_pwm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ struct pwmout_s
101101

102102
// Number of counts that the PWM output will make before a new PWM cycle starts
103103
uint32_t top_count;
104+
105+
// Number of counts that the PWM output will stay on for.
106+
// Zero = full off, top_count = full on
107+
uint32_t on_counts;
104108
};
105109

106110
#ifdef __cplusplus

0 commit comments

Comments
 (0)