Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: Picaso_4DGL-32PTU_Media.cpp
- Revision:
- 12:29f5ad896382
- Child:
- 13:1a0800957412
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Picaso_4DGL-32PTU_Media.cpp Wed Sep 14 13:27:37 2016 +0000 @@ -0,0 +1,163 @@ +// +// Picaso_4DGL-32PTU is a class to drive 4D Systems TFT touch screens with PICASO processor +// Tested with NUCLEO L152RE development board +// Copyright (C) <2016> Rihards Balass <rihards.balass@gmail.com> +// +// Picaso_4DGL-32PTU is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Picaso_4DGL-32PTU is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You can see GNU General Public License at <http://www.gnu.org/licenses/>. +// + +#include "mbed.h" +#include "Picaso_4DGL-32PTU.h" + +//************************************************************************** +// The Media Init command initialises a uSD/SD/SDHC memory card for further operations. +// The SD card is connected to the SPI (serial peripheral interface) of the PICASO-GFX2 chip. +//************************************************************************** +short PICASO_4DGL :: media_Init() { + + char command[2] = ""; + + command[0] = (MEDIA_INIT >> (8*1)) & 0xff; + command[1] = (MEDIA_INIT >> (8*0)) & 0xff; + + writeCOMMAND(command, 2); + short success = mediaInitResponse(); +#ifdef DEBUGMODE + pc.printf("\n\r DEBUG: uSD card INIT: %i\n\r", success); +#endif + return success; +} + +//************************************************************************** +// The Set Byte Address command sets the media memory internal +// Address pointer for access at a non-sector aligned byte address. +//************************************************************************** +bool PICASO_4DGL :: media_SetAdd(int address) { + + char command[6] = ""; + + command[0] = (MEDIA_SET_ADD >> (8*1)) & 0xff; + command[1] = (MEDIA_SET_ADD >> (8*0)) & 0xff; + command[2] = (address >> (8*3)) & 0xff; + command[3] = (address >> (8*2)) & 0xff; + command[4] = (address >> (8*1)) & 0xff; + command[5] = (address >> (8*0)) & 0xff; + + writeCOMMAND(command, 6); + bool success = getResponse(1); +#ifdef DEBUGMODE + pc.printf("\n\r DEBUG: Set byte address: %i\n\r", success); +#endif + return success; +} + +//************************************************************************** +// The Set Sector Address command sets the media memory internal Address pointer for sector access. +//************************************************************************** +bool PICASO_4DGL :: media_SetSector(int address) { + + char command[6] = ""; + + command[0] = (MEDIA_SET_SECTOR >> (8*1)) & 0xff; + command[1] = (MEDIA_SET_SECTOR >> (8*0)) & 0xff; + command[2] = (address >> (8*3)) & 0xff; + command[3] = (address >> (8*2)) & 0xff; + command[4] = (address >> (8*1)) & 0xff; + command[5] = (address >> (8*0)) & 0xff; + + writeCOMMAND(command, 6); + bool success = getResponse(1); +#ifdef DEBUGMODE + pc.printf("\n\r DEBUG: Set sector address: %i\n\r", success); +#endif + return success; +} + +//************************************************************************** +// The Read Sector command reads and returns 512 bytes (256 words) +// pointed to by the internal Sector pointer, determined by the +// “Set Sector Address” command. +// After the read the Sector pointer is automatically incremented by 1. +// Answer = acknowledge (byte) , status (word), block (sector) = 1 + 2 + 512 = 515 bytes +//************************************************************************** +bool PICASO_4DGL :: media_ReadSector() { + + char command[2] = ""; + + command[0] = (MEDIA_READ_SECTOR >> (8*1)) & 0xff; + command[1] = (MEDIA_READ_SECTOR >> (8*0)) & 0xff; + + writeCOMMAND(command, 2); + bool success = readSectorResponse(515); +#ifdef DEBUGMODE + pc.printf("\n\r DEBUG: Set sector address: %i\n\r", success); +#endif + return success; +} + +//************************************************************************** +// The Write Sector command writes 512 bytes (256 words) from a source memory +// block into the uSD card. After the write the Sect pointer is automatically incremented by 1. +// Response = acknowledge (byte) , status (word) +//************************************************************************** +bool PICASO_4DGL :: media_WriteSector(char *block) { + + char command[514] = ""; + + command[0] = (MEDIA_WRITE_SECTOR >> (8*1)) & 0xff; + command[1] = (MEDIA_WRITE_SECTOR >> (8*0)) & 0xff; + + int j = 2; + int k = 0; + for (int i = 513; i < 0; i++) { + command[j] = block + + writeCOMMAND(command, 2); + bool success = readSectorResponse(515); +#ifdef DEBUGMODE + pc.printf("\n\r DEBUG: Set sector address: %i\n\r", success); +#endif + return success; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +