1 /*
2 * Copyright (c) 2020 Hubert Miś
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/drivers/misc/ft8xx/ft8xx_common.h>
8
9 #include <zephyr/sys/byteorder.h>
10 #include "ft8xx_drv.h"
11
ft8xx_wr8(uint32_t address,uint8_t data)12 void ft8xx_wr8(uint32_t address, uint8_t data)
13 {
14 int err;
15
16 err = ft8xx_drv_write(address, &data, sizeof(data));
17 __ASSERT(err == 0, "Writing FT8xx data at 0x%x failed", address);
18 }
19
ft8xx_wr16(uint32_t address,uint16_t data)20 void ft8xx_wr16(uint32_t address, uint16_t data)
21 {
22 int err;
23 uint8_t buffer[2];
24
25 *(uint16_t *)buffer = sys_cpu_to_le16(data);
26 err = ft8xx_drv_write(address, buffer, sizeof(buffer));
27 __ASSERT(err == 0, "Writing FT8xx data at 0x%x failed", address);
28 }
29
ft8xx_wr32(uint32_t address,uint32_t data)30 void ft8xx_wr32(uint32_t address, uint32_t data)
31 {
32 int err;
33 uint8_t buffer[4];
34
35 *(uint32_t *)buffer = sys_cpu_to_le32(data);
36 err = ft8xx_drv_write(address, buffer, sizeof(buffer));
37 __ASSERT(err == 0, "Writing FT8xx data at 0x%x failed", address);
38 }
39
ft8xx_rd8(uint32_t address)40 uint8_t ft8xx_rd8(uint32_t address)
41 {
42 int err;
43 uint8_t data = 0;
44
45 err = ft8xx_drv_read(address, &data, sizeof(data));
46 __ASSERT(err == 0, "Reading FT8xx data from 0x%x failed", address);
47
48 return data;
49 }
50
ft8xx_rd16(uint32_t address)51 uint16_t ft8xx_rd16(uint32_t address)
52 {
53 int err;
54 uint8_t buffer[2] = {0};
55
56 err = ft8xx_drv_read(address, buffer, sizeof(buffer));
57 __ASSERT(err == 0, "Reading FT8xx data from 0x%x failed", address);
58
59 return sys_le16_to_cpu(*(const uint16_t *)buffer);
60 }
61
ft8xx_rd32(uint32_t address)62 uint32_t ft8xx_rd32(uint32_t address)
63 {
64 int err;
65 uint8_t buffer[4] = {0};
66
67 err = ft8xx_drv_read(address, buffer, sizeof(buffer));
68 __ASSERT(err == 0, "Reading FT8xx data from 0x%x failed", address);
69
70 return sys_le32_to_cpu(*(const uint32_t *)buffer);
71 }
72