2 * Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
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:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
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.
33 MY9221::MY9221 (uint8_t di, uint8_t dcki) {
34 mraa_result_t error = MRAA_SUCCESS;
38 m_clkPinCtx = mraa_gpio_init(dcki);
39 if (m_clkPinCtx == NULL) {
40 fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
44 m_dataPinCtx = mraa_gpio_init(di);
45 if (m_dataPinCtx == NULL) {
46 fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
50 // set direction (out)
51 error = mraa_gpio_dir(m_clkPinCtx, MRAA_GPIO_OUT);
52 if (error != MRAA_SUCCESS) {
53 mraa_result_print(error);
56 // set direction (out)
57 error = mraa_gpio_dir(m_dataPinCtx, MRAA_GPIO_OUT);
58 if (error != MRAA_SUCCESS) {
59 mraa_result_print(error);
64 mraa_result_t error = MRAA_SUCCESS;
65 error = mraa_gpio_close (m_dataPinCtx);
66 if (error != MRAA_SUCCESS) {
67 mraa_result_print(error);
69 error = mraa_gpio_close (m_clkPinCtx);
70 if (error != MRAA_SUCCESS) {
71 mraa_result_print(error);
76 MY9221::setBarLevel (uint8_t level) {
78 return MRAA_ERROR_INVALID_PARAMETER;
81 send16bitBlock (CMDMODE);
82 for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
83 uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
84 send16bitBlock (state);
91 mraa_result_t error = MRAA_SUCCESS;
92 error = mraa_gpio_write (m_dataPinCtx, LOW);
95 for(int idx = 0; idx < 4; idx++) {
96 error = mraa_gpio_write (m_dataPinCtx, HIGH);
97 error = mraa_gpio_write (m_dataPinCtx, LOW);
102 MY9221::send16bitBlock (short data) {
103 mraa_result_t error = MRAA_SUCCESS;
104 for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
105 uint32_t state = (data & 0x8000) ? HIGH : LOW;
106 error = mraa_gpio_write (m_dataPinCtx, state);
107 state = mraa_gpio_read (m_clkPinCtx);
115 error = mraa_gpio_write (m_clkPinCtx, state);