Private
Public Access
2
0

MAA version 0.2.0 moves to a standard C API

* Removed all C++ code and renamed all .cxx extensions to .c
* All functions are renamed to maa_ and modules are for example called maa_pwm
* Cmake can now 'make doc' using a Doxyfile.in to create documentation
* examples/ have been updated but swig generated API is untested

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-04-27 21:17:54 +01:00
parent 5a270191b5
commit a5a407e4b5
23 changed files with 389 additions and 736 deletions

146
api/pwm.h
View File

@@ -21,112 +21,66 @@
#include <stdio.h>
#include <fcntl.h>
namespace maa {
/** A PWM object, used for interacting with PWM output.
*
* Example:
* @code
* // Set up PWM object then cycle percentage 0-100.
*
* #include "maa.h"
*
* PWM pwm(3);
*
* int main() {
* pwm.period_us(7968750i); //Max Galileo Rev D
* pwm.enable(1);
*
* float value = 0;
* while(1) {
* pwm.write(value);
* sleep(0.5);
* if(value == 1.0) {
* value = 0;
* } else {
* value = value +0.1;
* }
* }
* }
* @endcode
*/
class PWM {
private:
typedef struct {
int chipid, pin;
FILE *duty_fp;
} pwm_t;
void write_period(int period);
void write_duty(int duty);
int setup_duty_fp();
int get_period();
int get_duty();
int maa_pwm_init(pwm_t* pwm, int chipin, int pin);
public:
/** Set the ouput duty-cycle percentage, as a float
*
* @param percentage A floating-point value representing percentage of output.
* The value should lie between 0.0f (representing on 0%) and 1.0f
* Values above or below this range will be set at either 0.0f or 1.0f.
*/
void maa_pwm_write(pwm_t* pwm, float percentage);
/** Create an PWM object
*
* @param chipid The chip in which the following pin is on.
* @param pin The PWM channel to operate on
*/
PWM(int chipid, int pin);
/** Read the ouput duty-cycle percentage, as a float
*
* @return percentage A floating-point value representing percentage of output.
* The value should lie between 0.0f (representing on 0%) and 1.0f
* Values above or below this range will be set at either 0.0f or 1.0f.
*/
float maa_pwm_read(pwm_t* pwm);
/** Set the ouput duty-cycle percentage, as a float
*
* @param percentage A floating-point value representing percentage of output.
* The value should lie between 0.0f (representing on 0%) and 1.0f
* Values above or below this range will be set at either 0.0f or 1.0f.
*/
void write(float percentage);
/** Set the PWM period as seconds represented in a float
*
* @param seconds Peroid represented as a float in seconds.
*/
void maa_pwm_period(pwm_t* pwm, float seconds);
/** Read the ouput duty-cycle percentage, as a float
*
* @return percentage A floating-point value representing percentage of output.
* The value should lie between 0.0f (representing on 0%) and 1.0f
* Values above or below this range will be set at either 0.0f or 1.0f.
*/
float read();
/** Set period. milli-oseconds.
* @param ms milli-seconds for period.
*/
void maa_pwm_period_ms(pwm_t* pwm, int ms);
/** Set the PWM period as seconds represented in a float
*
* @param seconds Peroid represented as a float in seconds.
*/
void period(float seconds);
/** Set period. microseconds
* @param ns microseconds as period.
*/
void maa_pwm_period_us(pwm_t* pwm, int us);
/** Set period. milli-oseconds.
* @param ms milli-seconds for period.
*/
void period_ms(int ms);
/** Set pulsewidth, As represnted by seconds in a (float).
* @param seconds The duration of a pulse
*/
void maa_pwm_pulsewidth(pwm_t* pwm, float seconds);
/** Set period. microseconds
* @param ns microseconds as period.
*/
void period_us(int us);
/** Set pulsewidth. Milliseconds
* @param ms milliseconds for pulsewidth.
*/
void maa_pwm_pulsewidth_ms(pwm_t* pwm, int ms);
/** Set pulsewidth, As represnted by seconds in a (float).
* @param seconds The duration of a pulse
*/
void pulsewidth(float seconds);
/** Set pulsewidth, microseconds.
* @param us microseconds for pulsewidth.
*/
void maa_pwm_pulsewidth_us(pwm_t* pwm, int us);
/** Set pulsewidth. Milliseconds
* @param ms milliseconds for pulsewidth.
*/
void pulsewidth_ms(int ms);
/** Set the enable status of the PWM pin. None zero will assume on with output being driven.
* and 0 will disable the output.
* @param enable enable status of pin
*/
void maa_pwm_enable(pwm_t* pwm, int enable);
/** Set pulsewidth, microseconds.
* @param us microseconds for pulsewidth.
*/
void pulsewidth_us(int us);
/** Set the enable status of the PWM pin. None zero will assume on with output being driven.
* and 0 will disable the output.
* @param enable enable status of pin
*/
void enable(int enable);
/** Close and unexport the PWM pin.
*/
void close();
};
}
/** Close and unexport the PWM pin.
*/
void maa_pwm_close(pwm_t* pwm);