blob: 1e657082afc3987f53657b2da0d457782354cdfe [file] [log] [blame]
zongqiang.zhang0c6a0882019-08-07 14:48:21 +08001/**
2 * \file STM32F10x.c
3 * \brief Device implementation for ST STM32F10x ARM Cortex-M3 MCUs
4 * Requires the use of ST's Standard Peripheral Library
5 * \author Andy Gock
6 * \todo Code is untested!
7 */
8
9/*
10 Copyright (c) 2012, Andy Gock
11
12 All rights reserved.
13
14 Redistribution and use in source and binary forms, with or without
15 modification, are permitted provided that the following conditions are met:
16 * Redistributions of source code must retain the above copyright
17 notice, this list of conditions and the following disclaimer.
18 * Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in the
20 documentation and/or other materials provided with the distribution.
21 * Neither the name of Andy Gock nor the
22 names of its contributors may be used to endorse or promote products
23 derived from this software without specific prior written permission.
24
25 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 DISCLAIMED. IN NO EVENT SHALL ANDY GOCK BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35*/
36
37/* Includes from CMSIS and Peripheral Library */
38#include "stm32f10x.h"
39#include "../sys_hw/timer.h"
40#include "glcd_spi.h"
41#include "ST7565R.h"
42
43void glcd_HW_init(void)
44{
45 /* Initialisation of GPIO and SPI */
46 GPIO_InitTypeDef GPIO_InitStructure;
47
48 /* Set up GPIO pins */
49 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
50
51 /* DC pin */
52 GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_DC_PIN;
53 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
54 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
55 GPIO_Init(CONTROLLER_SPI_DC_PORT, &GPIO_InitStructure);
56
57 /* RESET pin */
58 GPIO_InitStructure.GPIO_Pin = CONTROLLER_SPI_RST_PIN;
59 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
60 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
61 GPIO_Init(CONTROLLER_SPI_RST_PORT, &GPIO_InitStructure);
62
63 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
64 GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
65 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
66 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
67 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
68 GPIO_Init(GPIOA, &GPIO_InitStructure);
69
70 GLCD_BKL_ON();
71
72 /* Make sure chip is de-selected by default */
73 GLCD_DESELECT();
74
75 /* Initialise SPI */
76 spi_init();
77
78 /* Send reset pulse to LCD */
79 glcd_reset();
80 delay_ms(1);
81
82 glcd_ST7565R_init();
83
84 /* Set all dots black and hold for 0.5s, then clear it, we do this so we can visually check init sequence is working */
85// glcd_all_on();
86// delay_ms(50);
87 glcd_normal();
88
89 glcd_set_start_line(0);
90 glcd_clear_now();
91}
92
93void glcd_spi_write(uint8_t c)
94{
95 GLCD_SELECT();
96 spi_transive(c, 1000);
97 GLCD_DESELECT();
98}
99
100void glcd_reset(void)
101{
102 GLCD_SELECT();
103 GLCD_RESET_LOW();
104 delay_ms(2);
105 GLCD_RESET_HIGH();
106 GLCD_DESELECT();
107}
108/*void GLCD_BKL_ON(void)
109{
110 GPIO_SetBits(GPIOA, GPIO_Pin_15);
111}
112void GLCD_BKL_OFF(void)
113{
114 GPIO_ResetBits(GPIOA, GPIO_Pin_15);
115}*/