growing leaf (6 frames) and reverse

Dependencies:   Adafruit_GFX_i2c BLE_API USBDevice mbed

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
SamShiSS
Date:
Tue Jul 18 16:39:46 2017 +0000
Revision:
32:114e947a916b
unyte logo animation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
SamShiSS 32:114e947a916b 1 /*******************************************************************************
SamShiSS 32:114e947a916b 2 * Copyright (C) 2014 Maxim Integrated Products, Inc., All Rights Reserved.
SamShiSS 32:114e947a916b 3 *
SamShiSS 32:114e947a916b 4 * Permission is hereby granted, free of charge, to any person obtaining a
SamShiSS 32:114e947a916b 5 * copy of this software and associated documentation files (the "Software"),
SamShiSS 32:114e947a916b 6 * to deal in the Software without restriction, including without limitation
SamShiSS 32:114e947a916b 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
SamShiSS 32:114e947a916b 8 * and/or sell copies of the Software, and to permit persons to whom the
SamShiSS 32:114e947a916b 9 * Software is furnished to do so, subject to the following conditions:
SamShiSS 32:114e947a916b 10 *
SamShiSS 32:114e947a916b 11 * The above copyright notice and this permission notice shall be included
SamShiSS 32:114e947a916b 12 * in all copies or substantial portions of the Software.
SamShiSS 32:114e947a916b 13 *
SamShiSS 32:114e947a916b 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
SamShiSS 32:114e947a916b 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
SamShiSS 32:114e947a916b 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
SamShiSS 32:114e947a916b 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
SamShiSS 32:114e947a916b 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
SamShiSS 32:114e947a916b 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
SamShiSS 32:114e947a916b 20 * OTHER DEALINGS IN THE SOFTWARE.
SamShiSS 32:114e947a916b 21 *
SamShiSS 32:114e947a916b 22 * Except as contained in this notice, the name of Maxim Integrated
SamShiSS 32:114e947a916b 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
SamShiSS 32:114e947a916b 24 * Products, Inc. Branding Policy.
SamShiSS 32:114e947a916b 25 *
SamShiSS 32:114e947a916b 26 * The mere transfer of this software does not imply any licenses
SamShiSS 32:114e947a916b 27 * of trade secrets, proprietary technology, copyrights, patents,
SamShiSS 32:114e947a916b 28 * trademarks, maskwork rights, or any other form of intellectual
SamShiSS 32:114e947a916b 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
SamShiSS 32:114e947a916b 30 * ownership rights.
SamShiSS 32:114e947a916b 31 *******************************************************************************
SamShiSS 32:114e947a916b 32 */
SamShiSS 32:114e947a916b 33
SamShiSS 32:114e947a916b 34 /* $Revision: 3277 $ $Date: 2014-10-02 13:39:01 -0500 (Thu, 02 Oct 2014) $ */
SamShiSS 32:114e947a916b 35
SamShiSS 32:114e947a916b 36 #include "./mxc_config.h"
SamShiSS 32:114e947a916b 37
SamShiSS 32:114e947a916b 38 #include <stdint.h>
SamShiSS 32:114e947a916b 39 #include <string.h>
SamShiSS 32:114e947a916b 40
SamShiSS 32:114e947a916b 41 #include "./flc.h"
SamShiSS 32:114e947a916b 42 #include "./icc_regs.h"
SamShiSS 32:114e947a916b 43
SamShiSS 32:114e947a916b 44
SamShiSS 32:114e947a916b 45 int32_t FLC_Erase(uint32_t address, uint8_t erase_code, uint8_t unlock_key)
SamShiSS 32:114e947a916b 46 {
SamShiSS 32:114e947a916b 47 if(!MXC_ICC->ctrl_stat_f.enable) {
SamShiSS 32:114e947a916b 48 return -1;
SamShiSS 32:114e947a916b 49 }
SamShiSS 32:114e947a916b 50
SamShiSS 32:114e947a916b 51 mxc_flc_ctrl_t fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 52 fcntl.erase_code = 0; /* clear erase code */
SamShiSS 32:114e947a916b 53 fcntl.auto_incre_mode = 0; /* clear burst */
SamShiSS 32:114e947a916b 54 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 55
SamShiSS 32:114e947a916b 56 fcntl.flsh_unlock = unlock_key;
SamShiSS 32:114e947a916b 57 fcntl.erase_code = erase_code;
SamShiSS 32:114e947a916b 58 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 59
SamShiSS 32:114e947a916b 60 MXC_FLC->faddr = (address & MXC_FLC_PAGE_ERASE_MSK); /* set bank address */
SamShiSS 32:114e947a916b 61
SamShiSS 32:114e947a916b 62 fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 63 fcntl.page_erase = 1; /* set and start erase operation */
SamShiSS 32:114e947a916b 64 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 65
SamShiSS 32:114e947a916b 66 do {
SamShiSS 32:114e947a916b 67 fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 68 } while (fcntl.pending); /* wait until done */
SamShiSS 32:114e947a916b 69
SamShiSS 32:114e947a916b 70 fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 71 fcntl.erase_code = 0; /* lock flash */
SamShiSS 32:114e947a916b 72 fcntl.flsh_unlock = 0;
SamShiSS 32:114e947a916b 73 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 74
SamShiSS 32:114e947a916b 75 return 0;
SamShiSS 32:114e947a916b 76 }
SamShiSS 32:114e947a916b 77
SamShiSS 32:114e947a916b 78 int32_t FLC_WriteBlock(uint32_t address, const void *data, uint32_t length, uint8_t unlock_key)
SamShiSS 32:114e947a916b 79 {
SamShiSS 32:114e947a916b 80 uint32_t *word = (uint32_t *) data;
SamShiSS 32:114e947a916b 81
SamShiSS 32:114e947a916b 82 if(!MXC_ICC->ctrl_stat_f.enable) {
SamShiSS 32:114e947a916b 83 return -1;
SamShiSS 32:114e947a916b 84 }
SamShiSS 32:114e947a916b 85
SamShiSS 32:114e947a916b 86 if(address & 3) { /* address needs to be aligned with word */
SamShiSS 32:114e947a916b 87 return -1;
SamShiSS 32:114e947a916b 88 }
SamShiSS 32:114e947a916b 89
SamShiSS 32:114e947a916b 90 length = length & 0xfffffffc;
SamShiSS 32:114e947a916b 91
SamShiSS 32:114e947a916b 92 mxc_flc_ctrl_t fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 93 fcntl.erase_code = 0; /* clear erase code */
SamShiSS 32:114e947a916b 94 fcntl.auto_incre_mode = 0; /* clear burst */
SamShiSS 32:114e947a916b 95 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 96
SamShiSS 32:114e947a916b 97 fcntl.flsh_unlock = unlock_key; /* set unlock */
SamShiSS 32:114e947a916b 98 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 99
SamShiSS 32:114e947a916b 100 while (length)
SamShiSS 32:114e947a916b 101 {
SamShiSS 32:114e947a916b 102 MXC_FLC->faddr = address;
SamShiSS 32:114e947a916b 103 MXC_FLC->fdata = *word;
SamShiSS 32:114e947a916b 104
SamShiSS 32:114e947a916b 105 fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 106 fcntl.write = 1;
SamShiSS 32:114e947a916b 107 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 108
SamShiSS 32:114e947a916b 109 address += 4;
SamShiSS 32:114e947a916b 110 word++;
SamShiSS 32:114e947a916b 111 length -= 4;
SamShiSS 32:114e947a916b 112
SamShiSS 32:114e947a916b 113 do {
SamShiSS 32:114e947a916b 114 fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 115 } while (fcntl.pending);
SamShiSS 32:114e947a916b 116 }
SamShiSS 32:114e947a916b 117
SamShiSS 32:114e947a916b 118 fcntl = MXC_FLC->ctrl_f;
SamShiSS 32:114e947a916b 119 fcntl.erase_code = 0; /* lock flash */
SamShiSS 32:114e947a916b 120 fcntl.flsh_unlock = 0;
SamShiSS 32:114e947a916b 121 MXC_FLC->ctrl_f = fcntl;
SamShiSS 32:114e947a916b 122
SamShiSS 32:114e947a916b 123 return 0;
SamShiSS 32:114e947a916b 124 }
SamShiSS 32:114e947a916b 125