Driver of ST X-NUCLEO-OUT01A1 Industrial Digital output expansion board based on ISO8200BQ component.
Dependents: HelloWorld_OUT01A1
XNucleoOUT01A1.cpp@0:c77427077cff, 2018-02-12 (annotated)
- Committer:
- nikapov
- Date:
- Mon Feb 12 17:22:42 2018 +0000
- Revision:
- 0:c77427077cff
Initial revision.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nikapov | 0:c77427077cff | 1 | /** |
nikapov | 0:c77427077cff | 2 | ****************************************************************************** |
nikapov | 0:c77427077cff | 3 | * @file XNucleoOUT01A1.cpp |
nikapov | 0:c77427077cff | 4 | * @author ST CLab |
nikapov | 0:c77427077cff | 5 | * @version V1.0.0 |
nikapov | 0:c77427077cff | 6 | * @date 1 February 2018 |
nikapov | 0:c77427077cff | 7 | * @brief Implementation of XNucleoOUT01A1 class |
nikapov | 0:c77427077cff | 8 | ****************************************************************************** |
nikapov | 0:c77427077cff | 9 | * @attention |
nikapov | 0:c77427077cff | 10 | * |
nikapov | 0:c77427077cff | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
nikapov | 0:c77427077cff | 12 | * |
nikapov | 0:c77427077cff | 13 | * Redistribution and use in source and binary forms, with or without modification, |
nikapov | 0:c77427077cff | 14 | * are permitted provided that the following conditions are met: |
nikapov | 0:c77427077cff | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
nikapov | 0:c77427077cff | 16 | * this list of conditions and the following disclaimer. |
nikapov | 0:c77427077cff | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
nikapov | 0:c77427077cff | 18 | * this list of conditions and the following disclaimer in the documentation |
nikapov | 0:c77427077cff | 19 | * and/or other materials provided with the distribution. |
nikapov | 0:c77427077cff | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
nikapov | 0:c77427077cff | 21 | * may be used to endorse or promote products derived from this software |
nikapov | 0:c77427077cff | 22 | * without specific prior written permission. |
nikapov | 0:c77427077cff | 23 | * |
nikapov | 0:c77427077cff | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
nikapov | 0:c77427077cff | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
nikapov | 0:c77427077cff | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
nikapov | 0:c77427077cff | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
nikapov | 0:c77427077cff | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
nikapov | 0:c77427077cff | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
nikapov | 0:c77427077cff | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
nikapov | 0:c77427077cff | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
nikapov | 0:c77427077cff | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
nikapov | 0:c77427077cff | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
nikapov | 0:c77427077cff | 34 | * |
nikapov | 0:c77427077cff | 35 | ****************************************************************************** |
nikapov | 0:c77427077cff | 36 | */ |
nikapov | 0:c77427077cff | 37 | |
nikapov | 0:c77427077cff | 38 | /* Includes ----------------------------------------------------------------*/ |
nikapov | 0:c77427077cff | 39 | |
nikapov | 0:c77427077cff | 40 | #include "XNucleoOUT01A1.h" |
nikapov | 0:c77427077cff | 41 | |
nikapov | 0:c77427077cff | 42 | /* Macros --------------------------------------------------------------------*/ |
nikapov | 0:c77427077cff | 43 | |
nikapov | 0:c77427077cff | 44 | #define SET_PIN(pin) ((pin != NC) ? new DigitalOut(pin) : NULL) |
nikapov | 0:c77427077cff | 45 | |
nikapov | 0:c77427077cff | 46 | /* Class Implementation ------------------------------------------------------*/ |
nikapov | 0:c77427077cff | 47 | |
nikapov | 0:c77427077cff | 48 | /** Constructor |
nikapov | 0:c77427077cff | 49 | * @param ctl_mode Control mode, direct or sync. |
nikapov | 0:c77427077cff | 50 | * @param CTL_MODE_PIN Control mode pin, if connected then jumper J4 overrides ctl_mode parameter |
nikapov | 0:c77427077cff | 51 | * @param OUT_EN Output enable pin. |
nikapov | 0:c77427077cff | 52 | * @param N_SYNC Input-to-output synchronization signal. Active low. |
nikapov | 0:c77427077cff | 53 | * @param N_LOAD Load input data signal. Active low. |
nikapov | 0:c77427077cff | 54 | * @param INx Channel x input pin, NC if not connected |
nikapov | 0:c77427077cff | 55 | */ |
nikapov | 0:c77427077cff | 56 | |
nikapov | 0:c77427077cff | 57 | XNucleoOUT01A1::XNucleoOUT01A1(control_mode_t ctl_mode, PinName CTL_MODE_PIN, |
nikapov | 0:c77427077cff | 58 | PinName OUT_EN, PinName N_SYNC, PinName N_LOAD, PinName IN1, |
nikapov | 0:c77427077cff | 59 | PinName IN2, PinName IN3, PinName IN4, PinName IN5, PinName IN6, |
nikapov | 0:c77427077cff | 60 | PinName IN7, PinName IN8) |
nikapov | 0:c77427077cff | 61 | : iso8200bq(OUT_EN, N_SYNC, N_LOAD) |
nikapov | 0:c77427077cff | 62 | { |
nikapov | 0:c77427077cff | 63 | |
nikapov | 0:c77427077cff | 64 | if (CTL_MODE_PIN != NC) { // ctl_mode selected by jumper J4 |
nikapov | 0:c77427077cff | 65 | _ctl_mode_pin = new DigitalIn(CTL_MODE_PIN); |
nikapov | 0:c77427077cff | 66 | if (*_ctl_mode_pin == 1) { |
nikapov | 0:c77427077cff | 67 | _mode = mode_sync; |
nikapov | 0:c77427077cff | 68 | } else { |
nikapov | 0:c77427077cff | 69 | _mode = mode_direct; |
nikapov | 0:c77427077cff | 70 | } |
nikapov | 0:c77427077cff | 71 | } else { // ctl_mode provided by the user |
nikapov | 0:c77427077cff | 72 | _mode = ctl_mode; |
nikapov | 0:c77427077cff | 73 | |
nikapov | 0:c77427077cff | 74 | } |
nikapov | 0:c77427077cff | 75 | |
nikapov | 0:c77427077cff | 76 | if (_mode == mode_direct) { // set the component in direct mode |
nikapov | 0:c77427077cff | 77 | iso8200bq.direct_mode(); |
nikapov | 0:c77427077cff | 78 | } |
nikapov | 0:c77427077cff | 79 | |
nikapov | 0:c77427077cff | 80 | _in_array[0] = SET_PIN(IN1); |
nikapov | 0:c77427077cff | 81 | _in_array[1] = SET_PIN(IN2); |
nikapov | 0:c77427077cff | 82 | _in_array[2] = SET_PIN(IN3); |
nikapov | 0:c77427077cff | 83 | _in_array[3] = SET_PIN(IN4); |
nikapov | 0:c77427077cff | 84 | _in_array[4] = SET_PIN(IN5); |
nikapov | 0:c77427077cff | 85 | _in_array[5] = SET_PIN(IN6); |
nikapov | 0:c77427077cff | 86 | _in_array[6] = SET_PIN(IN7); |
nikapov | 0:c77427077cff | 87 | _in_array[7] = SET_PIN(IN8); |
nikapov | 0:c77427077cff | 88 | |
nikapov | 0:c77427077cff | 89 | } |
nikapov | 0:c77427077cff | 90 | |
nikapov | 0:c77427077cff | 91 | |
nikapov | 0:c77427077cff | 92 | /** |
nikapov | 0:c77427077cff | 93 | * |
nikapov | 0:c77427077cff | 94 | * @brief Enable outputs |
nikapov | 0:c77427077cff | 95 | * |
nikapov | 0:c77427077cff | 96 | * @param enable Enable outputs when true, disable otherwise. |
nikapov | 0:c77427077cff | 97 | */ |
nikapov | 0:c77427077cff | 98 | |
nikapov | 0:c77427077cff | 99 | void XNucleoOUT01A1::enable_outputs(bool enable) { |
nikapov | 0:c77427077cff | 100 | iso8200bq.enable_outputs(enable); |
nikapov | 0:c77427077cff | 101 | } |
nikapov | 0:c77427077cff | 102 | |
nikapov | 0:c77427077cff | 103 | /** |
nikapov | 0:c77427077cff | 104 | * |
nikapov | 0:c77427077cff | 105 | * @brief Set input status, also loaded into input buffer when in sync mode |
nikapov | 0:c77427077cff | 106 | * |
nikapov | 0:c77427077cff | 107 | * @param input_values Bitmask of input values, bit x represents INx pin's value |
nikapov | 0:c77427077cff | 108 | */ |
nikapov | 0:c77427077cff | 109 | void XNucleoOUT01A1::set_inputs(uint8_t input_values) { |
nikapov | 0:c77427077cff | 110 | |
nikapov | 0:c77427077cff | 111 | if (_mode == mode_sync) { |
nikapov | 0:c77427077cff | 112 | iso8200bq.sync_mode_load_inputs(); |
nikapov | 0:c77427077cff | 113 | } |
nikapov | 0:c77427077cff | 114 | |
nikapov | 0:c77427077cff | 115 | for (int i=0; i<8; i++) { |
nikapov | 0:c77427077cff | 116 | int value = (input_values >> i) & 0x01; |
nikapov | 0:c77427077cff | 117 | if (_in_array[i] != NULL) { |
nikapov | 0:c77427077cff | 118 | *_in_array[i] = value; |
nikapov | 0:c77427077cff | 119 | } |
nikapov | 0:c77427077cff | 120 | } |
nikapov | 0:c77427077cff | 121 | } |
nikapov | 0:c77427077cff | 122 | |
nikapov | 0:c77427077cff | 123 | /** |
nikapov | 0:c77427077cff | 124 | * |
nikapov | 0:c77427077cff | 125 | * @brief Update output status according to input buffer when in sync mode |
nikapov | 0:c77427077cff | 126 | * |
nikapov | 0:c77427077cff | 127 | * @param input_values Bitmask of input values, bit x represents INx pin's value |
nikapov | 0:c77427077cff | 128 | */ |
nikapov | 0:c77427077cff | 129 | void XNucleoOUT01A1::update_outputs(void) { |
nikapov | 0:c77427077cff | 130 | |
nikapov | 0:c77427077cff | 131 | if (_mode == mode_sync) { |
nikapov | 0:c77427077cff | 132 | iso8200bq.sync_mode_update_outputs(); |
nikapov | 0:c77427077cff | 133 | } |
nikapov | 0:c77427077cff | 134 | } |