Driver of ST X-NUCLEO-OUT01A1 Industrial Digital output expansion board based on ISO8200BQ component.
Dependents: HelloWorld_OUT01A1
Revision 0:c77427077cff, committed 2018-02-12
- Comitter:
- nikapov
- Date:
- Mon Feb 12 17:22:42 2018 +0000
- Commit message:
- Initial revision.
Changed in this revision
diff -r 000000000000 -r c77427077cff ISO8200BQ/ISO8200BQ.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ISO8200BQ/ISO8200BQ.cpp Mon Feb 12 17:22:42 2018 +0000 @@ -0,0 +1,139 @@ +/** + ****************************************************************************** + * @file ISO8200BQ.cpp + * @author ST CLab + * @version V1.0.0 + * @date 1 February 2018 + * @brief Implementation of a ISO8200BQ class + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + /* Includes ------------------------------------------------------------------*/ + +#include "ISO8200BQ.h" + + +/* Class Implementation ------------------------------------------------------*/ + + /** Constructor + * @param OUT_EN Output enable pin. + * @param N_SYNC Input-to-output synchronization signal. Active low. + * @param N_LOAD Load input data signal. Active low. + */ + + ISO8200BQ::ISO8200BQ(PinName OUT_EN, PinName N_SYNC, + PinName N_LOAD) : _out_en(OUT_EN), _n_sync(N_SYNC), _n_load(N_LOAD) + { + /* start with the component disabled*/ + _out_en = 0; + }; + + /** + * @brief Getting the ID of the component. + * @param id Pointer to an allocated variable to store the ID into. + * @retval "0" in case of success, an error code otherwise. + */ + int ISO8200BQ::read_id(uint8_t *id = NULL) + { + return 0; + } + + /** + * + * @brief One time device initialization + * + * @param void + * @retval "0" in case of success, an error code otherwise. + */ + int ISO8200BQ::init(void *init) + { + /* initalize with SYNC and LOAD signals disabled*/ + _n_sync = _n_load = 1; + return 0; + } + + /** + * + * @brief Enable/Disable all outputs + * + * @param enable Enable the outputs when true, disable otherwise + */ + void ISO8200BQ::enable_outputs(bool enable) { + _out_en = enable ? 1 : 0; + } + + /** + * + * @brief Get outputs enabling status + * + * @retval Returns true if outputs are enabled, false otherwise + */ + bool ISO8200BQ::are_outputs_enabled (void) { + return (_out_en == 0) ? false : true; + } + + /** + * + * @brief Load input pin status into input buffer (synch mode) + * + */ + void ISO8200BQ::sync_mode_load_inputs (void) { + _n_load = 1; //disabled + _n_sync = 1; //disabled + wait_us(20); //tdis(sync) + _n_load = 0; //enabled + } + + /** + * + * @brief Update outputs accordingly to input buffer (synch mode) + * + */ + void ISO8200BQ::sync_mode_update_outputs(void) { + wait_us(100); // tw(load) + _n_load = 1; //disabled + wait_us(1); //tsu(load) + _n_sync = 0; //enabled + wait_us(100); // tw(sync) + _n_sync = 1; // trigger output updates (on rising edge) + } + + /** + * + * @brief Update outputs accordingly to input pins (direct mode) + * + */ + void ISO8200BQ::direct_mode (void) { + _n_load = 0; //enabled + _n_sync = 0; //enabled + wait_us(1); //tinld + } + + \ No newline at end of file
diff -r 000000000000 -r c77427077cff ISO8200BQ/ISO8200BQ.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ISO8200BQ/ISO8200BQ.h Mon Feb 12 17:22:42 2018 +0000 @@ -0,0 +1,76 @@ +/** + ****************************************************************************** + * @file ISO8200BQ.h + * @author ST CLab + * @version V1.0.0 + * @date 1 February 2018 + * @brief Abstract class of a ISO8200BQ octal smart power solid state-relay + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __ISO8200BQ_H__ +#define __ISO8200BQ_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include <mbed.h> +#include <assert.h> +#include "Component.h" + + +/* Class Declaration ---------------------------------------------------------*/ + +/** + * Abstract class of a ISO8200BQ octal smart power solid state-relay. + */ +class ISO8200BQ : public Component +{ + public: + ISO8200BQ (PinName OUT_EN, PinName N_SYNC, + PinName N_LOAD); + virtual int init(void *init); + virtual int read_id(uint8_t *id); + void enable_outputs(bool enable); + bool are_outputs_enabled (void); + void sync_mode_load_inputs (void); + void sync_mode_update_outputs(void); + void direct_mode (void); + + private: + DigitalOut _out_en; + DigitalOut _n_sync; + DigitalOut _n_load; +}; + +#endif \ No newline at end of file
diff -r 000000000000 -r c77427077cff ISO8200BQ/Interfaces/Component.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ISO8200BQ/Interfaces/Component.h Mon Feb 12 17:22:42 2018 +0000 @@ -0,0 +1,81 @@ +/** + ****************************************************************************** + * @file Component.h + * @author AST + * @version V1.0.0 + * @date April 13th, 2015 + * @brief This file contains the abstract class describing the interface of a + * generic component. + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Define to prevent recursive inclusion -------------------------------------*/ + +#ifndef __COMPONENT_CLASS_H +#define __COMPONENT_CLASS_H + + +/* Includes ------------------------------------------------------------------*/ + +#include <stdint.h> + + +/* Classes ------------------------------------------------------------------*/ + +/** + * An abstract class for Generic components. + */ +class Component { +public: + + /** + * @brief Initializing the component. + * @param[in] init pointer to device specific initalization structure. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int init(void *init) = 0; + + /** + * @brief Getting the ID of the component. + * @param[out] id pointer to an allocated variable to store the ID into. + * @retval "0" in case of success, an error code otherwise. + */ + virtual int read_id(uint8_t *id) = 0; + + /** + * @brief Destructor. + */ + virtual ~Component() {}; +}; + +#endif /* __COMPONENT_CLASS_H */ + +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
diff -r 000000000000 -r c77427077cff XNucleoOUT01A1.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XNucleoOUT01A1.cpp Mon Feb 12 17:22:42 2018 +0000 @@ -0,0 +1,134 @@ +/** + ****************************************************************************** + * @file XNucleoOUT01A1.cpp + * @author ST CLab + * @version V1.0.0 + * @date 1 February 2018 + * @brief Implementation of XNucleoOUT01A1 class + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + /* Includes ----------------------------------------------------------------*/ + +#include "XNucleoOUT01A1.h" + +/* Macros --------------------------------------------------------------------*/ + +#define SET_PIN(pin) ((pin != NC) ? new DigitalOut(pin) : NULL) + +/* Class Implementation ------------------------------------------------------*/ + + /** Constructor + * @param ctl_mode Control mode, direct or sync. + * @param CTL_MODE_PIN Control mode pin, if connected then jumper J4 overrides ctl_mode parameter + * @param OUT_EN Output enable pin. + * @param N_SYNC Input-to-output synchronization signal. Active low. + * @param N_LOAD Load input data signal. Active low. + * @param INx Channel x input pin, NC if not connected + */ + + XNucleoOUT01A1::XNucleoOUT01A1(control_mode_t ctl_mode, PinName CTL_MODE_PIN, + PinName OUT_EN, PinName N_SYNC, PinName N_LOAD, PinName IN1, + PinName IN2, PinName IN3, PinName IN4, PinName IN5, PinName IN6, + PinName IN7, PinName IN8) + : iso8200bq(OUT_EN, N_SYNC, N_LOAD) + { + + if (CTL_MODE_PIN != NC) { // ctl_mode selected by jumper J4 + _ctl_mode_pin = new DigitalIn(CTL_MODE_PIN); + if (*_ctl_mode_pin == 1) { + _mode = mode_sync; + } else { + _mode = mode_direct; + } + } else { // ctl_mode provided by the user + _mode = ctl_mode; + + } + + if (_mode == mode_direct) { // set the component in direct mode + iso8200bq.direct_mode(); + } + + _in_array[0] = SET_PIN(IN1); + _in_array[1] = SET_PIN(IN2); + _in_array[2] = SET_PIN(IN3); + _in_array[3] = SET_PIN(IN4); + _in_array[4] = SET_PIN(IN5); + _in_array[5] = SET_PIN(IN6); + _in_array[6] = SET_PIN(IN7); + _in_array[7] = SET_PIN(IN8); + + } + + + /** + * + * @brief Enable outputs + * + * @param enable Enable outputs when true, disable otherwise. + */ + + void XNucleoOUT01A1::enable_outputs(bool enable) { + iso8200bq.enable_outputs(enable); + } + + /** + * + * @brief Set input status, also loaded into input buffer when in sync mode + * + * @param input_values Bitmask of input values, bit x represents INx pin's value + */ + void XNucleoOUT01A1::set_inputs(uint8_t input_values) { + + if (_mode == mode_sync) { + iso8200bq.sync_mode_load_inputs(); + } + + for (int i=0; i<8; i++) { + int value = (input_values >> i) & 0x01; + if (_in_array[i] != NULL) { + *_in_array[i] = value; + } + } + } + + /** + * + * @brief Update output status according to input buffer when in sync mode + * + * @param input_values Bitmask of input values, bit x represents INx pin's value + */ + void XNucleoOUT01A1::update_outputs(void) { + + if (_mode == mode_sync) { + iso8200bq.sync_mode_update_outputs(); + } + } \ No newline at end of file
diff -r 000000000000 -r c77427077cff XNucleoOUT01A1.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XNucleoOUT01A1.h Mon Feb 12 17:22:42 2018 +0000 @@ -0,0 +1,88 @@ +/** + ****************************************************************************** + * @file XNucleoOUT01A1.h + * @author ST CLab + * @version V1.0.0 + * @date 1 February 2018 + * @brief Abstract class of X-NUCLEO-OUT01A1 board + ****************************************************************************** + * @attention + * + * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of STMicroelectronics nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************** + */ + + +/* Prevent recursive inclusion -----------------------------------------------*/ + +#ifndef __XNUCLEOOUT01A1_H__ +#define __XNUCLEOOUT01A1_H__ + + +/* Includes ------------------------------------------------------------------*/ + +#include "ISO8200BQ.h" + +/* Class Declaration ---------------------------------------------------------*/ + +/* Types ---------------------------------------------------------------------*/ + +typedef enum +{ + mode_sync, + mode_direct +} control_mode_t; + +/** + * Abstract class of X-NUCLEO_OUT01A1 Expansion Board. + * Default reflecting STM32 Nucleos pinout. + */ + +class XNucleoOUT01A1 +{ +public: + + XNucleoOUT01A1(control_mode_t ctl_mode=mode_direct, + PinName CTL_MODE_PIN=NC, PinName OUT_EN=A3, PinName N_SYNC=A4, + PinName N_LOAD=A5, PinName IN1=A0, PinName IN2=A1, PinName IN3=NC, + PinName IN4=A2, PinName IN5=D5, PinName IN6=D4, PinName IN7=D14, + PinName IN8=D15); + + void set_inputs(uint8_t input_values); + + void update_outputs(void); + + void enable_outputs(bool enable); + +private: + ISO8200BQ iso8200bq; + control_mode_t _mode; + DigitalIn *_ctl_mode_pin; + DigitalOut *_in_array[8]; +}; + + +#endif \ No newline at end of file