-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAnalogOutClass.h
74 lines (63 loc) · 2.48 KB
/
AnalogOutClass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @file AnalogOutClass.h
* @author Leonardo Cavagnis
* @brief Header file for the Analog OUT connector of the Portenta Machine Control library.
*
* This library allows to configure the analog channels as PWM, to set frequency and value.
*/
#ifndef __ANALOGOUT_CLASS_H
#define __ANALOGOUT_CLASS_H
/* Includes -------------------------------------------------------------------*/
#include <Arduino.h>
#include <mbed.h>
#include "pins_mc.h"
/* Class ----------------------------------------------------------------------*/
/**
* @class AnalogOutClass
* @brief Class for the Analog OUT connector of the Portenta Machine Control.
*/
class AnalogOutClass {
public:
/**
* @brief Construct an Analog Output writer for the Portenta Machine Control.
*
* @param ao0_pin The analog pin number of the channel 0
* @param ao1_pin The analog pin number of the channel 1
* @param ao2_pin The analog pin number of the channel 2
* @param ao3_pin The analog pin number of the channel 2
*/
AnalogOutClass(PinName ao0_pin = MC_AO_AO0_PIN, PinName ao1_pin = MC_AO_AO1_PIN, PinName ao2_pin = MC_AO_AO2_PIN, PinName ao3_pin = MC_AO_AO3_PIN);
/**
* @brief Destruct the AnalogOutClass object.
*
* This destructor releases any resources used by the AnalogOutClass object.
*/
~AnalogOutClass();
/**
* @brief Initialize the PWM, configure the default frequency for all channels (500Hz)
*
* @return true If the PWM is successfully initialized, false Otherwise
*/
bool begin();
/**
* @brief Set the PWM period (frequency) on the selected channel
*
* @param channel selected channel
* @param period_ms PWM period in ms
*/
void setPeriod(int channel, uint8_t period_ms);
/**
* @brief Set output voltage value on the selected channel
*
* @param channel selected channel
* @param voltage desired output voltage (max 10.5V)
*/
void write(int channel, float voltage);
private:
mbed::PwmOut _ao0; // PWM output for Analog Out channel 0
mbed::PwmOut _ao1; // PWM output for Analog Out channel 1
mbed::PwmOut _ao2; // PWM output for Analog Out channel 2
mbed::PwmOut _ao3; // PWM output for Analog Out channel 3
};
extern AnalogOutClass MachineControl_AnalogOut;
#endif /* __ANALOGOUT_CLASS_H */