1 /* 2 * Author: Jon Trulson <jtrulson@ics.com> 3 * Copyright (c) 2015 Intel Corporation. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be 14 * included in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 #pragma once 25 26 #include <mraa/pwm.h> 27 28 namespace upm { 29 /** 30 * @brief CJQ4435 MOSFET library 31 * @defgroup cjq4435 libupm-cjq4435 32 * @ingroup seeed gpio pwm electric robok 33 */ 34 35 /** 36 * @library cjq4435 37 * @sensor cjq4435 38 * @comname Grove MOSFET 39 * @altname CJQ4435 40 * @type electric 41 * @man seeed 42 * @con gpio pwm 43 * @kit robok 44 * 45 * @brief API for the CJQ4435 MOSFET 46 * 47 * UPM module for the CJQ4435 MOSFET. It was developed using the 48 * Grove MOSFET module. A MOSFET is like a switch, but it can 49 * switch much faster than a mechanical relay. Here, we implement 50 * support via MRAA pulse width modulation (PWM) functions. 51 * Note: available periods vary depending on 52 * the capabilities of your device. 53 * 54 * @image html cjq4435.jpg 55 * @snippet cjq4435.cxx Interesting 56 */ 57 class CJQ4435 { 58 public: 59 /** 60 * CJQ4435 constructor 61 * 62 * @param pin Digital pin to use; this pin must be PWM-capable 63 */ 64 CJQ4435(int pin); 65 66 /** 67 * CJQ4435 destructor 68 */ 69 ~CJQ4435(); 70 71 /** 72 * Sets a period in microseconds 73 * 74 * @param us Period in microseconds 75 */ 76 void setPeriodUS(int us); 77 78 /** 79 * Sets a period in milliseconds 80 * 81 * @param ms Period in milliseconds 82 */ 83 void setPeriodMS(int ms); 84 85 /** 86 * Sets a period in seconds 87 * 88 * @param seconds Period in seconds 89 */ 90 void setPeriodSeconds(float seconds); 91 92 /** 93 * Enables output 94 * 95 * @param enable Enables PWM output if true, disables otherwise 96 */ 97 void enable(bool enable); 98 99 /** 100 * Sets a duty cycle. Duty cycle is a floating-point number 101 * between 0.0 (always off) and 1.0 (always on). It represents a 102 * proportion of time, per period, during which the output is 103 * driven high. 104 * 105 * @param dutyCycle Duty cycle to use 106 */ 107 void setDutyCycle(float dutyCycle); 108 109 /** 110 * Shortcut to turn the output to continuous on (high) 111 */ 112 void on(); 113 114 /** 115 * Shortcut to turn the output to continuous off (low) 116 */ 117 void off(); 118 119 private: 120 bool m_enabled; 121 mraa_pwm_context m_pwm; 122 }; 123 } 124 125 126