blob: 79ba5490b1d182cdf38935a6d016e8068985722d [file] [log] [blame]
Damien George784e0232017-01-24 16:56:03 +11001/*
2 * This file is part of the MicroPython project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
Damien George4e487002018-03-02 16:01:18 +11006 * Copyright (c) 2016-2018 Damien P. George
Damien George784e0232017-01-24 16:56:03 +11007 *
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 George784e0232017-01-24 16:56:03 +110026#ifndef MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H
27#define MICROPY_INCLUDED_DRIVERS_MEMORY_SPIFLASH_H
28
Damien George4e487002018-03-02 16:01:18 +110029#include "drivers/bus/qspi.h"
Damien George784e0232017-01-24 16:56:03 +110030#include "extmod/machine_spi.h"
31
Damien George4e487002018-03-02 16:01:18 +110032enum {
33 MP_SPIFLASH_BUS_SPI,
34 MP_SPIFLASH_BUS_QSPI,
35};
36
37typedef 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 George784e0232017-01-24 16:56:03 +110052typedef struct _mp_spiflash_t {
Damien George4e487002018-03-02 16:01:18 +110053 const mp_spiflash_config_t *config;
54 volatile uint32_t flags;
Damien George784e0232017-01-24 16:56:03 +110055} mp_spiflash_t;
56
57void mp_spiflash_init(mp_spiflash_t *self);
Damien George4e487002018-03-02 16:01:18 +110058void mp_spiflash_flush(mp_spiflash_t *self);
Damien George784e0232017-01-24 16:56:03 +110059void mp_spiflash_read(mp_spiflash_t *self, uint32_t addr, size_t len, uint8_t *dest);
60int 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