|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#include <bsp/bsp.h> |
| 21 | +#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common |
| 22 | +#include <bus/drivers/i2c_common.h> |
| 23 | +#else |
| 24 | +#include <hal/hal_i2c.h> |
| 25 | +#endif |
| 26 | + |
| 27 | +#include <lv_conf.h> |
| 28 | +#include <lcd_itf.h> |
| 29 | + |
| 30 | +#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common |
| 31 | +static struct bus_i2c_node lcd; |
| 32 | +static struct bus_i2c_node_cfg lcd_i2c_cfg = { |
| 33 | + .node_cfg.bus_name = MYNEWT_VAL(LCD_I2C_DEV_NAME), |
| 34 | + .addr = MYNEWT_VAL(LCD_I2C_ADDR), |
| 35 | + .freq = MYNEWT_VAL(LCD_I2C_FREQ), |
| 36 | +}; |
| 37 | +static struct os_dev *lcd_dev; |
| 38 | +#else |
| 39 | +#endif |
| 40 | + |
| 41 | +void |
| 42 | +lcd_itf_write_color_data(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, void *pixels) |
| 43 | +{ |
| 44 | + uint8_t *color_data = pixels; |
| 45 | + size_t size = ((x2 - x1 + 1) * (y2 - y1 + 1)) >> 3; |
| 46 | + |
| 47 | +#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common |
| 48 | + color_data[-1] = 0x40; |
| 49 | + bus_node_write(lcd_dev, color_data - 1, size + 1, 1000, 0); |
| 50 | +#else |
| 51 | + color_data[-1] = 0x40; |
| 52 | + struct hal_i2c_master_data data = { |
| 53 | + .address = MYNEWT_VAL(LCD_I2C_ADDR), |
| 54 | + .buffer = color_data - 1, |
| 55 | + .len = size + 1, |
| 56 | + }; |
| 57 | + hal_i2c_master_write(0, &data, 1000, 1); |
| 58 | +#endif |
| 59 | +} |
| 60 | + |
| 61 | +void |
| 62 | +lcd_ift_write_cmd(const uint8_t *cmd, int cmd_length) |
| 63 | +{ |
| 64 | + uint8_t buf[cmd_length + 1]; |
| 65 | + |
| 66 | + buf[0] = 0; |
| 67 | + for (int i = 0; i < cmd_length; ++i) { |
| 68 | + buf[i + 1] = cmd[i]; |
| 69 | + } |
| 70 | +#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common |
| 71 | + bus_node_write(lcd_dev, buf, cmd_length + 1, 1000, 0); |
| 72 | +#else |
| 73 | + struct hal_i2c_master_data data = { |
| 74 | + .address = MYNEWT_VAL(LCD_I2C_ADDR), |
| 75 | + .buffer = buf, |
| 76 | + .len = cmd_length + 1, |
| 77 | + }; |
| 78 | + hal_i2c_master_write(0, &data, 1000, 1); |
| 79 | +#endif |
| 80 | +} |
| 81 | + |
| 82 | + |
| 83 | +void |
| 84 | +lcd_itf_init(void) |
| 85 | +{ |
| 86 | +#if MYNEWT_PKG_apache_mynewt_core__hw_bus_drivers_i2c_common |
| 87 | + int rc; |
| 88 | + struct bus_node_callbacks cbs = {}; |
| 89 | + |
| 90 | + bus_node_set_callbacks((struct os_dev *)&lcd, &cbs); |
| 91 | + |
| 92 | + rc = bus_i2c_node_create("display", &lcd, &lcd_i2c_cfg, NULL); |
| 93 | + assert(rc == 0); |
| 94 | + lcd_dev = os_dev_open("display", 0, NULL); |
| 95 | +#endif |
| 96 | +} |
0 commit comments