Lines Matching +full:spi +full:- +full:addr
4 * SPDX-License-Identifier: Apache-2.0
11 #include <zephyr/drivers/spi.h>
14 * @file Sample app using the Fujitsu MB85RS64V FRAM through SPI.
25 static int mb85rs64v_access(const struct device *spi, in mb85rs64v_access() argument
27 uint8_t cmd, uint16_t addr, void *data, size_t len) in mb85rs64v_access() argument
46 access[1] = (addr >> 8) & 0xFF; in mb85rs64v_access()
47 access[2] = addr & 0xFF; in mb85rs64v_access()
58 return spi_transceive(spi, spi_cfg, &tx, &rx); in mb85rs64v_access()
64 return spi_write(spi, spi_cfg, &tx); in mb85rs64v_access()
68 static int mb85rs64v_read_id(const struct device *spi, in mb85rs64v_read_id() argument
74 err = mb85rs64v_access(spi, spi_cfg, in mb85rs64v_read_id()
78 return -EIO; in mb85rs64v_read_id()
82 return -EIO; in mb85rs64v_read_id()
86 return -EIO; in mb85rs64v_read_id()
90 return -EIO; in mb85rs64v_read_id()
94 return -EIO; in mb85rs64v_read_id()
100 static int write_bytes(const struct device *spi, struct spi_config *spi_cfg, in write_bytes() argument
101 uint16_t addr, uint8_t *data, uint32_t num_bytes) in write_bytes() argument
106 err = mb85rs64v_access(spi, spi_cfg, in write_bytes()
110 return -EIO; in write_bytes()
114 err = mb85rs64v_access(spi, spi_cfg, in write_bytes()
115 MB85RS64V_WRITE_CMD, addr, data, num_bytes); in write_bytes()
117 printk("Error during SPI write\n"); in write_bytes()
118 return -EIO; in write_bytes()
124 static int read_bytes(const struct device *spi, struct spi_config *spi_cfg, in read_bytes() argument
125 uint16_t addr, uint8_t *data, uint32_t num_bytes) in read_bytes() argument
130 err = mb85rs64v_access(spi, spi_cfg, in read_bytes()
131 MB85RS64V_READ_CMD, addr, data, num_bytes); in read_bytes()
133 printk("Error during SPI read\n"); in read_bytes()
134 return -EIO; in read_bytes()
142 const struct device *spi; in main() local
148 spi = DEVICE_DT_GET(DT_ALIAS(spi_1)); in main()
149 if (!device_is_ready(spi)) { in main()
150 printk("SPI device %s is not ready\n", spi->name); in main()
158 err = mb85rs64v_read_id(spi, &spi_cfg); in main()
164 /* Do one-byte read/write */ in main()
166 err = write_bytes(spi, &spi_cfg, 0x00, data, 1); in main()
175 err = write_bytes(spi, &spi_cfg, 0x01, data, 1); in main()
184 err = read_bytes(spi, &spi_cfg, 0x00, data, 1); in main()
193 err = read_bytes(spi, &spi_cfg, 0x01, data, 1); in main()
201 /* Do multi-byte read/write */ in main()
209 err = write_bytes(spi, &spi_cfg, 0x00, cmp_data, sizeof(cmp_data)); in main()
218 err = read_bytes(spi, &spi_cfg, 0x00, data, sizeof(data)); in main()
231 err = -EIO; in main()