hadif azli / Mbed 2 deprecated TEST123

Dependencies:   mbed Blynk

Committer:
lixianyu
Date:
Mon Jun 13 02:21:11 2016 +0000
Revision:
1:0e75de2a5d21
Parent:
0:d8f4c441e032
u8glib???????????????????????????Adafruit_GFX????OLED????????bitmap??????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lixianyu 0:d8f4c441e032 1 /*
lixianyu 0:d8f4c441e032 2
lixianyu 0:d8f4c441e032 3 u8g_com_raspberrypi_hw_spi.c
lixianyu 0:d8f4c441e032 4
lixianyu 0:d8f4c441e032 5 Universal 8bit Graphics Library
lixianyu 0:d8f4c441e032 6
lixianyu 0:d8f4c441e032 7 Copyright (c) 2012, olikraus@gmail.com
lixianyu 0:d8f4c441e032 8 All rights reserved.
lixianyu 0:d8f4c441e032 9
lixianyu 0:d8f4c441e032 10 Redistribution and use in source and binary forms, with or without modification,
lixianyu 0:d8f4c441e032 11 are permitted provided that the following conditions are met:
lixianyu 0:d8f4c441e032 12
lixianyu 0:d8f4c441e032 13 * Redistributions of source code must retain the above copyright notice, this list
lixianyu 0:d8f4c441e032 14 of conditions and the following disclaimer.
lixianyu 0:d8f4c441e032 15
lixianyu 0:d8f4c441e032 16 * Redistributions in binary form must reproduce the above copyright notice, this
lixianyu 0:d8f4c441e032 17 list of conditions and the following disclaimer in the documentation and/or other
lixianyu 0:d8f4c441e032 18 materials provided with the distribution.
lixianyu 0:d8f4c441e032 19
lixianyu 0:d8f4c441e032 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
lixianyu 0:d8f4c441e032 21 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
lixianyu 0:d8f4c441e032 22 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
lixianyu 0:d8f4c441e032 23 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
lixianyu 0:d8f4c441e032 24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
lixianyu 0:d8f4c441e032 25 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
lixianyu 0:d8f4c441e032 26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
lixianyu 0:d8f4c441e032 27 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
lixianyu 0:d8f4c441e032 28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
lixianyu 0:d8f4c441e032 29 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
lixianyu 0:d8f4c441e032 30 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
lixianyu 0:d8f4c441e032 31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
lixianyu 0:d8f4c441e032 32 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
lixianyu 0:d8f4c441e032 33
lixianyu 0:d8f4c441e032 34
lixianyu 0:d8f4c441e032 35 Assumes, that
lixianyu 0:d8f4c441e032 36 MOSI is at PORTB, Pin 3
lixianyu 0:d8f4c441e032 37 and
lixianyu 0:d8f4c441e032 38 SCK is at PORTB, Pin 5
lixianyu 0:d8f4c441e032 39
lixianyu 0:d8f4c441e032 40 Update for ATOMIC operation done (01 Jun 2013)
lixianyu 0:d8f4c441e032 41 U8G_ATOMIC_OR(ptr, val)
lixianyu 0:d8f4c441e032 42 U8G_ATOMIC_AND(ptr, val)
lixianyu 0:d8f4c441e032 43 U8G_ATOMIC_START()
lixianyu 0:d8f4c441e032 44 U8G_ATOMIC_END()
lixianyu 0:d8f4c441e032 45
lixianyu 0:d8f4c441e032 46
lixianyu 0:d8f4c441e032 47
lixianyu 0:d8f4c441e032 48 */
lixianyu 0:d8f4c441e032 49
lixianyu 0:d8f4c441e032 50 #include "u8g.h"
lixianyu 0:d8f4c441e032 51
lixianyu 0:d8f4c441e032 52
lixianyu 0:d8f4c441e032 53
lixianyu 0:d8f4c441e032 54 #if defined(U8G_RASPBERRY_PI)
lixianyu 0:d8f4c441e032 55
lixianyu 0:d8f4c441e032 56 #include <wiringPiSPI.h>
lixianyu 0:d8f4c441e032 57 #include <wiringPi.h>
lixianyu 0:d8f4c441e032 58 #include <stdio.h>
lixianyu 0:d8f4c441e032 59 #include <stdlib.h>
lixianyu 0:d8f4c441e032 60 #include <errno.h>
lixianyu 0:d8f4c441e032 61
lixianyu 0:d8f4c441e032 62 uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
lixianyu 0:d8f4c441e032 63 {
lixianyu 0:d8f4c441e032 64 switch(msg)
lixianyu 0:d8f4c441e032 65 {
lixianyu 0:d8f4c441e032 66 case U8G_COM_MSG_STOP:
lixianyu 0:d8f4c441e032 67 break;
lixianyu 0:d8f4c441e032 68
lixianyu 0:d8f4c441e032 69 case U8G_COM_MSG_INIT:
lixianyu 0:d8f4c441e032 70 // check wiringPi setup
lixianyu 0:d8f4c441e032 71 if (wiringPiSetup() == -1)
lixianyu 0:d8f4c441e032 72 {
lixianyu 0:d8f4c441e032 73 printf("wiringPi-Error\n");
lixianyu 0:d8f4c441e032 74 exit(1);
lixianyu 0:d8f4c441e032 75 }
lixianyu 0:d8f4c441e032 76
lixianyu 0:d8f4c441e032 77 if (wiringPiSPISetup (0, 100000) < 0)
lixianyu 0:d8f4c441e032 78 {
lixianyu 0:d8f4c441e032 79 printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ;
lixianyu 0:d8f4c441e032 80 exit (1) ;
lixianyu 0:d8f4c441e032 81 }
lixianyu 0:d8f4c441e032 82
lixianyu 0:d8f4c441e032 83 u8g_SetPIOutput(u8g, U8G_PI_RESET);
lixianyu 0:d8f4c441e032 84 u8g_SetPIOutput(u8g, U8G_PI_A0);
lixianyu 0:d8f4c441e032 85
lixianyu 0:d8f4c441e032 86 break;
lixianyu 0:d8f4c441e032 87
lixianyu 0:d8f4c441e032 88 case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
lixianyu 0:d8f4c441e032 89 u8g_SetPILevel(u8g, U8G_PI_A0, arg_val);
lixianyu 0:d8f4c441e032 90 break;
lixianyu 0:d8f4c441e032 91
lixianyu 0:d8f4c441e032 92 case U8G_COM_MSG_CHIP_SELECT:
lixianyu 0:d8f4c441e032 93 /* Done by the SPI hardware */
lixianyu 0:d8f4c441e032 94 break;
lixianyu 0:d8f4c441e032 95
lixianyu 0:d8f4c441e032 96 case U8G_COM_MSG_RESET:
lixianyu 0:d8f4c441e032 97 u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val);
lixianyu 0:d8f4c441e032 98 break;
lixianyu 0:d8f4c441e032 99
lixianyu 0:d8f4c441e032 100 case U8G_COM_MSG_WRITE_BYTE:
lixianyu 0:d8f4c441e032 101 wiringPiSPIDataRW (0, &arg_val, 1) ;
lixianyu 0:d8f4c441e032 102 break;
lixianyu 0:d8f4c441e032 103
lixianyu 0:d8f4c441e032 104 case U8G_COM_MSG_WRITE_SEQ:
lixianyu 0:d8f4c441e032 105 wiringPiSPIDataRW (0, arg_ptr, arg_val);
lixianyu 0:d8f4c441e032 106 break;
lixianyu 0:d8f4c441e032 107
lixianyu 0:d8f4c441e032 108 case U8G_COM_MSG_WRITE_SEQ_P:
lixianyu 0:d8f4c441e032 109 wiringPiSPIDataRW (0, arg_ptr, arg_val);
lixianyu 0:d8f4c441e032 110 break;
lixianyu 0:d8f4c441e032 111 }
lixianyu 0:d8f4c441e032 112 return 1;
lixianyu 0:d8f4c441e032 113 }
lixianyu 0:d8f4c441e032 114
lixianyu 0:d8f4c441e032 115 #else
lixianyu 0:d8f4c441e032 116
lixianyu 0:d8f4c441e032 117 uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
lixianyu 0:d8f4c441e032 118 {
lixianyu 0:d8f4c441e032 119 return 1;
lixianyu 0:d8f4c441e032 120 }
lixianyu 0:d8f4c441e032 121
lixianyu 0:d8f4c441e032 122 #endif
lixianyu 0:d8f4c441e032 123
lixianyu 0:d8f4c441e032 124
lixianyu 0:d8f4c441e032 125