Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the MicroPython project, http://micropython.org/ |
| 3 | * |
| 4 | * The MIT License (MIT) |
| 5 | * |
Damien George | 4e48700 | 2018-03-02 16:01:18 +1100 | [diff] [blame^] | 6 | * Copyright (c) 2016-2018 Damien P. George |
Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 7 | * |
| 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | * of this software and associated documentation files (the "Software"), to deal |
| 10 | * in the Software without restriction, including without limitation the rights |
| 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 12 | * copies of the Software, and to permit persons to whom the Software is |
| 13 | * furnished to do so, subject to the following conditions: |
| 14 | * |
| 15 | * The above copyright notice and this permission notice shall be included in |
| 16 | * all copies or substantial portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 24 | * THE SOFTWARE. |
| 25 | */ |
Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 26 | #ifndef MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H |
| 27 | #define MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H |
| 28 | |
Damien George | 4e48700 | 2018-03-02 16:01:18 +1100 | [diff] [blame^] | 29 | #include "drivers/bus/qspi.h" |
Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 30 | #include "extmod/machine_spi.h" |
| 31 | |
Damien George | 4e48700 | 2018-03-02 16:01:18 +1100 | [diff] [blame^] | 32 | enum { |
| 33 | MP_SPIFLASH_BUS_SPI, |
| 34 | MP_SPIFLASH_BUS_QSPI, |
| 35 | }; |
| 36 | |
| 37 | typedef struct _mp_spiflash_config_t { |
| 38 | uint32_t bus_kind; |
| 39 | union { |
| 40 | struct { |
| 41 | mp_hal_pin_obj_t cs; |
| 42 | void *data; |
| 43 | const mp_machine_spi_p_t *proto; |
| 44 | } u_spi; |
| 45 | struct { |
| 46 | void *data; |
| 47 | const mp_qspi_proto_t *proto; |
| 48 | } u_qspi; |
| 49 | } bus; |
| 50 | } mp_spiflash_config_t; |
| 51 | |
Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 52 | typedef struct _mp_spiflash_t { |
Damien George | 4e48700 | 2018-03-02 16:01:18 +1100 | [diff] [blame^] | 53 | const mp_spiflash_config_t *config; |
| 54 | volatile uint32_t flags; |
Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 55 | } mp_spiflash_t; |
| 56 | |
| 57 | void mp_spiflash_init(mp_spiflash_t *self); |
Damien George | 4e48700 | 2018-03-02 16:01:18 +1100 | [diff] [blame^] | 58 | void mp_spiflash_flush(mp_spiflash_t *self); |
Damien George | 784e023 | 2017-01-24 16:56:03 +1100 | [diff] [blame] | 59 | void mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest); |
| 60 | int mp_spiflash_write(mp_spiflash_t *self, uint32_t addr, size_t len, const uint8_t *src); |
| 61 | |
| 62 | #endif // MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H |