Browse Source

Initial commit

master
Simon Vikstrom 5 years ago
commit
d4fa03715e
17 changed files with 706 additions and 0 deletions
  1. +47
    -0
      .gitignore
  2. +3
    -0
      .gitmodules
  3. +208
    -0
      Makefile.binary
  4. +28
    -0
      Makefile.nrf51
  5. +29
    -0
      Makefile.nrf52
  6. +28
    -0
      README.md
  7. +12
    -0
      config/nrf52_components_config.h
  8. +10
    -0
      drivers/hd44780/Makefile.mk
  9. +85
    -0
      drivers/hd44780/nrf_hd44780.c
  10. +43
    -0
      drivers/hd44780/nrf_hd44780.h
  11. +16
    -0
      drivers/u8g/Makefile.mk
  12. +140
    -0
      drivers/u8g/u8g_arm.c
  13. +8
    -0
      drivers/u8g/u8g_arm.h
  14. +7
    -0
      platform/delay.mk
  15. +7
    -0
      platform/hal.mk
  16. +14
    -0
      platform/spi.mk
  17. +21
    -0
      platform/uart.mk

+ 47
- 0
.gitignore View File

@ -0,0 +1,47 @@
# Object files
*.o
*.ko
*.obj
*.elf
.depend
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
# QtCreator
*.includes
*.files
# Build output
_build
# Qt creator generated files
*.config
*.creator
*.creator.user
sdk

+ 3
- 0
.gitmodules View File

@ -0,0 +1,3 @@
[submodule "external/u8glib"]
path = external/u8glib
url = https://github.com/olikraus/u8glib

+ 208
- 0
Makefile.binary View File

@ -0,0 +1,208 @@
include $(ROOT)/Makefile.config
REAL_PWD=$(shell echo $$PWD)
NRFJPROG ?= nrfjprog
OPENOCD ?= openocd
OPENOCD_IFACE ?= interface/stlink-v2.cfg
OPENOCD_TARGET ?= target/$(NRF_TARGET).cfg
ifeq ("$(PROJECT_NAME)","")
PROJECT_NAME := $(lastword $(subst /, , $(REAL_PWD)))
endif
MAKEFILE_NAME := $(MAKEFILE_LIST)
MAKEFILE_DIR := $(dir $(MAKEFILE_NAME) )
TEMPLATE_PATH = $(NRF5_SDK)/components/toolchain/gcc
ifeq ($(OS),Windows_NT)
include $(TEMPLATE_PATH)/Makefile.windows
else
include $(TEMPLATE_PATH)/Makefile.posix
endif
MK := mkdir
RM := rm -rf
ifeq ("$(VERBOSE)","1")
NO_ECHO :=
else
NO_ECHO := @
endif
# Toolchain commands
CC := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc'
AS := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as'
AR := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar' -r
LD := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld'
NM := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm'
OBJDUMP := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump'
OBJCOPY := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy'
SIZE := '$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-size'
SED := /bin/env sed
#function for removing duplicates in a list
remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-out $(firstword $1),$1))))
#source common to all targets
C_SOURCE_FILES += \
$(NRF5_SDK)/components/toolchain/system_$(NRF_TARGET).c \
#assembly files common to all targets
ASM_SOURCE_FILES = $(NRF5_SDK)/components/toolchain/gcc/gcc_startup_$(NRF_TARGET).s
#includes common to all targets
INC_PATHS += -I$(NRF5_SDK)/components/toolchain/gcc
INC_PATHS += -I$(NRF5_SDK)/components/toolchain
INC_PATHS += -I$(NRF5_SDK)/components/toolchain/CMSIS/Include/
INC_PATHS += -I.
INC_PATHS += -I$(NRF5_SDK)/components/device
INC_PATHS_NODUP = $(call remduplicates, $(INC_PATHS))
OBJECT_DIRECTORY = _build
LISTING_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_BINARY_DIRECTORY = $(OBJECT_DIRECTORY)
OUTPUT_FILENAME := firmware-$(NRF_TARGET)
# Sorting removes duplicates
BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
# Set target specific CFLAGS, LDFLAGS and ASMFLAGS
include $(ROOT)/Makefile.$(NRF_TARGET)
#default target - first one defined
default: firmware
#building all targets
all:
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e firmware
#target for printing all targets
help:
@echo following targets are available:
@echo firmware
# Allow duplicate source files for easier dependency management
C_SOURCE_FILE_NAMES_DUP = $(notdir $(C_SOURCE_FILES))
C_SOURCE_FILE_NAMES = $(call remduplicates, $(C_SOURCE_FILE_NAMES_DUP))
C_PATHS = $(call remduplicates, $(dir $(C_SOURCE_FILES) ) )
C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILE_NAMES:.c=.o) )
ASM_SOURCE_FILE_NAMES = $(notdir $(ASM_SOURCE_FILES))
ASM_PATHS = $(call remduplicates, $(dir $(ASM_SOURCE_FILES) ))
ASM_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASM_SOURCE_FILE_NAMES:.s=.o) )
vpath %.c $(C_PATHS)
vpath %.s $(ASM_PATHS)
OBJECTS = $(C_OBJECTS) $(ASM_OBJECTS)
firmware: $(LINKER_SCRIPT)
firmware: $(PROJECT_NAME).includes $(PROJECT_NAME).files
firmware: $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
$(NO_ECHO)$(MAKE) -f $(MAKEFILE_NAME) -C $(MAKEFILE_DIR) -e finalize
## Create build directories
$(BUILD_DIRECTORIES):
echo $(MAKEFILE_NAME)
$(MK) $@
# Create objects from C SRC files
$(OBJECT_DIRECTORY)/%.o: %.c
@echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -c -o $@ $<
# Depend file, editing a header file triggers rebuild on affected sources
.depend: $(C_SOURCE_FILE_NAMES)
@echo Building depend file
@rm -f ./.depend
$(NO_ECHO)$(CC) $(CFLAGS) $(INC_PATHS) -MM $^ > ./.depend;
@$(SED) -i -r 's/^(\w)/$(OBJECT_DIRECTORY)\/\1/g' .depend
@# Generate QtCreator files
@# Generate .includes file
@rm -f $(PROJECT_NAME).includes
@echo $(INC_PATHS_NODUP) | $(SED) -r 's/ /\n/g' | $(SED) 's/^-I//' > $(PROJECT_NAME).includes
@# Generate .files file
@rm -f $(PROJECT_NAME).files
@tr '\n' ' ' < .depend | sed 's/\\//g' | sed 's/[^ ]*://g' | sed 's/\s\+/\n/g' | sort | uniq > $(PROJECT_NAME).files
depend: .depend
-include .depend
# Assemble files
$(OBJECT_DIRECTORY)/%.o: %.s
@echo Compiling file: $(notdir $<)
$(NO_ECHO)$(CC) $(ASMFLAGS) $(INC_PATHS) -c -o $@ $<
# Link
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: check_sdk_path $(BUILD_DIRECTORIES) $(OBJECTS)
@echo Linking target: $(OUTPUT_FILENAME).out
$(NO_ECHO)$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
## Create binary .bin file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
@echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
@echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
finalize: genbin genhex echosize
genbin:
@echo Preparing: $(OUTPUT_FILENAME).bin
$(NO_ECHO)$(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
## Create binary .hex file from the .out file
genhex:
@echo Preparing: $(OUTPUT_FILENAME).hex
$(NO_ECHO)$(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
echosize:
-@echo ''
$(NO_ECHO)$(SIZE) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
-@echo ''
clean:
$(RM) $(BUILD_DIRECTORIES)
cleanobj:
$(RM) $(BUILD_DIRECTORIES)/*.o
deploy: $(MAKECMDGOALS)
@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
$(NRFJPROG) --erasepage 0x0-0x80000 -f $(NRF_TARGET)
$(NRFJPROG) --program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex -f $(NRF_TARGET)
$(NRFJPROG) --reset -f $(NRF_TARGET)
deploy-openocd: $(MAKECMDGOALS)
@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
$(OPENOCD) -f $(OPENOCD_IFACE) -f $(OPENOCD_TARGET) -c "init" -c "reset halt" -c "program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex 0 verify" -c "reset run" -c "exit"
erase-openocd: $(MAKECMDGOALS)
@echo Erasing...
$(OPENOCD) -f $(OPENOCD_IFACE) -f $(OPENOCD_TARGET) -c "init; reset halt; $(NRF_TARGET) mass_erase; shutdown"
## Flash softdevice (TODO)

+ 28
- 0
Makefile.nrf51 View File

@ -0,0 +1,28 @@
#flags common to all targets
CFLAGS += -DBOARD_PCA10028
CFLAGS += -DNRF51
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -O3 -g3
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DBOARD_PCA10028
ASMFLAGS += -DNRF51
ASMFLAGS += -DBSP_DEFINES_ONLY

+ 29
- 0
Makefile.nrf52 View File

@ -0,0 +1,29 @@
#flags common to all targets
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DBOARD_PCA10040
CFLAGS += -DNRF52
CFLAGS += -DBSP_DEFINES_ONLY
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -O3 -g3
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums
# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
LDFLAGS += -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs -lc -lnosys
# Assembler flags
ASMFLAGS += -x assembler-with-cpp
ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DNRF52
ASMFLAGS += -DBSP_DEFINES_ONLY
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET

+ 28
- 0
README.md View File

@ -0,0 +1,28 @@
# nrf52-components
This repository contains useful components to use on the nRF52 such as LCD drivers. More stuff is on the way.
It also contains some example applications.
This repository is basically just a playground, not something to depend on or trust.
Modules/drivers:
- [x] hd44780
- [x] u8glib
- [x] uart
- [ ] uart proxy (forward from one uart to another)
- [ ] SD card
Feel free to create issues with feature requests.
### Examples
| Location | Description |
| ---------------------------- |:------------:|
| `/examples/hd44780` | Prints text to a 2-row hd44780 display using the provided driver. |
| `/examples/u8g_test` | Displays test graphics on an LCD usisng U8G |
| `/examples/uart_test` | Prints text to UART and echos input. |
| `/examples/uart_to_lcd` | Echos UART and prints received bytes on an LCD using U8G. |

+ 12
- 0
config/nrf52_components_config.h View File

@ -0,0 +1,12 @@
#ifndef _NRF52_COMPONENTS_CONFIG_H
#define _NRF52_COMPONENTS_CONFIG_H
#define U8G_PIN_SCK (22)
#define U8G_PIN_DATA (23)
#define U8G_PIN_DC (24)
#define U8G_PIN_SCE (25)
#define U8G_PIN_RST ( 2)
#endif

+ 10
- 0
drivers/hd44780/Makefile.mk View File

@ -0,0 +1,10 @@
# Include me in your Makefile to build and add includes
# Don't forget to set a correct ROOT
include $(ROOT)/platform/hal.mk
include $(ROOT)/platform/delay.mk
C_SOURCE_FILES += $(ROOT)/drivers/hd44780/nrf_hd44780.c
INC_PATHS += -I$(ROOT)/drivers/hd44780

+ 85
- 0
drivers/hd44780/nrf_hd44780.c View File

@ -0,0 +1,85 @@
// Based on https://devzone.nordicsemi.com/question/58042/lcd-display-driver/?answer=58611#post-id-58611
#include "nrf_hd44780.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
void lcd_output_upper(uint8_t data)
{
if(data & 0x80) nrf_gpio_pin_set(LCD_PIN_B7);
else nrf_gpio_pin_clear(LCD_PIN_B7);
if(data & 0x40) nrf_gpio_pin_set(LCD_PIN_B6);
else nrf_gpio_pin_clear(LCD_PIN_B6);
if(data & 0x20) nrf_gpio_pin_set(LCD_PIN_B5);
else nrf_gpio_pin_clear(LCD_PIN_B5);
if(data & 0x10) nrf_gpio_pin_set(LCD_PIN_B4);
else nrf_gpio_pin_clear(LCD_PIN_B4);
}
void lcd_write8(uint8_t data)
{
lcd_output_upper(data);
LCD_PULSE_CLOCK;
lcd_output_upper(data << 4);
LCD_PULSE_CLOCK;
}
void lcd_enable_4bit_mode(bool two_line_display, bool big_characters)
{
uint8_t cmd_byte = LCD_CMD_FUNCTION_SET;
cmd_byte |= (two_line_display ? 0x08 : 0x00);
cmd_byte |= (big_characters ? 0x04 : 0x00);
lcd_write8(cmd_byte);
nrf_delay_us(40);
}
void lcd_clear_display()
{
LCD_REGISTER_SELECT_COMMAND;
lcd_write8(0x01);
nrf_delay_us(5000);
}
void lcd_on_off_control(bool on, bool cursor_on, bool cursor_blink)
{
LCD_REGISTER_SELECT_COMMAND;
lcd_write8(0x08 | (on ? 0x04 : 0x00) | (cursor_on ? 0x02 : 0x00) | (cursor_blink ? 0x01 : 0x00));
nrf_delay_us(50);
}
void lcd_set_cgram_address(uint8_t addr)
{
LCD_REGISTER_SELECT_COMMAND;
lcd_write8(0x40 | (addr & 0x3F));
nrf_delay_us(37);
}
void lcd_set_ddram_address(uint8_t addr)
{
LCD_REGISTER_SELECT_COMMAND;
lcd_write8(0x80 | (addr & 0x7F));
nrf_delay_us(37);
}
void lcd_write_string(char *string, uint32_t pos, bool lower_line)
{
lcd_set_ddram_address(pos + (lower_line ? 0x40 : 0x00));
while(*string)
{
LCD_REGISTER_SELECT_DATA;
lcd_write8(*string++);
nrf_delay_us(37);
}
}
void lcd_init()
{
nrf_gpio_range_cfg_output(LCD_PIN_BASE, LCD_PIN_BASE+5);
nrf_delay_us(15000);
nrf_gpio_pin_clear(LCD_PIN_RS); // Register select command
nrf_gpio_pin_clear(LCD_PIN_CLK); // CLK idle
}

+ 43
- 0
drivers/hd44780/nrf_hd44780.h View File

@ -0,0 +1,43 @@
// Based on https://devzone.nordicsemi.com/question/58042/lcd-display-driver/?answer=58611#post-id-58611
#ifndef __NRF_HD44780_H__
#define __NRF_HD44780_H__
#include <stdint.h>
#include <stdbool.h>
#define LCD_PULSE_CLOCK do{nrf_gpio_pin_clear(LCD_PIN_CLK);nrf_delay_us(1);nrf_gpio_pin_set(LCD_PIN_CLK);nrf_delay_us(1);nrf_gpio_pin_clear(LCD_PIN_CLK);nrf_delay_us(1);}while(0)
#define LCD_CMD_FUNCTION_SET 0x20
#define LCD_CLK_SET nrf_gpio_pin_clear(LCD_PIN_CLK)
#define LCD_CLK_CLEAR nrf_gpio_pin_set(LCD_PIN_CLK)
#define LCD_REGISTER_SELECT_COMMAND nrf_gpio_pin_clear(LCD_PIN_RS)
#define LCD_REGISTER_SELECT_DATA nrf_gpio_pin_set(LCD_PIN_RS)
#define LCD_PIN_BASE 11
#define LCD_PIN_RS (LCD_PIN_BASE + 4)
#define LCD_PIN_CLK (LCD_PIN_BASE + 5)
#define LCD_PIN_B4 (LCD_PIN_BASE + 0)
#define LCD_PIN_B5 (LCD_PIN_BASE + 1)
#define LCD_PIN_B6 (LCD_PIN_BASE + 2)
#define LCD_PIN_B7 (LCD_PIN_BASE + 3)
void lcd_output_upper(uint8_t data);
void lcd_write8(uint8_t data);
void lcd_enable_4bit_mode(bool two_line_display, bool big_characters);
void lcd_clear_display(void);
void lcd_on_off_control(bool on, bool cursor_on, bool cursor_blink);
void lcd_set_cgram_address(uint8_t addr);
void lcd_set_ddram_address(uint8_t addr);
void lcd_write_string(char *string, uint32_t pos, bool lower_line);
void lcd_init(void);
#endif

+ 16
- 0
drivers/u8g/Makefile.mk View File

@ -0,0 +1,16 @@
# Include me in your Makefile to build and add includes
# Don't forget to set a correct ROOT
include $(ROOT)/platform/hal.mk
include $(ROOT)/platform/delay.mk
C_SOURCE_FILES += \
$(wildcard $(ROOT)/drivers/u8g/*.c) \
$(wildcard $(ROOT)/external/u8glib/csrc/*.c) \
$(wildcard $(ROOT)/external/u8glib/fntsrc/*.c) \
INC_PATHS += -I$(ROOT)/drivers/u8g
INC_PATHS += -I$(ROOT)/external/u8glib/csrc

+ 140
- 0
drivers/u8g/u8g_arm.c View File

@ -0,0 +1,140 @@
#include "u8g_arm.h"
#include "nrf_delay.h"
#include "nrf_drv_spi.h"
#include "nrf_gpio.h"
#include "app_util_platform.h"
#include "nrf52_components_config.h"
/*
PIN CONFIGURATION
U8G_PIN_SCK SCK CLOCK max 4 Mb/s
U8G_PIN_MOSI MOSI Data out
U8G_PIN_DC DC Data/Command (high=data, low=command) - toggle on last bit
U8G_PIN_SCE SCE Chip Enable (low = active)
U8G_PIN_RST RES Reset (low = active)
*/
#if !defined(U8G_PIN_SCK) \
|| !defined(U8G_PIN_DATA) \
|| !defined(U8G_PIN_DC) \
|| !defined(U8G_PIN_SCE) \
|| !defined(U8G_PIN_RST)
# error Check your pin configuration. See nrf52_components_config.h (U8G_PIN_SCK etc)
#endif
static const nrf_drv_spi_t m_spi_master_0 = NRF_DRV_SPI_INSTANCE(0);
static void spi_init(int freq)
{
uint32_t err_code;
nrf_drv_spi_config_t const config =
{
.sck_pin = U8G_PIN_SCK,
.mosi_pin = U8G_PIN_DATA,
.miso_pin = NRF_DRV_SPI_PIN_NOT_USED,
.ss_pin = NRF_DRV_SPI_PIN_NOT_USED,
.irq_priority = APP_IRQ_PRIORITY_LOW,
.orc = 0xCC,
.frequency = freq,
.mode = NRF_DRV_SPI_MODE_0,
.bit_order = NRF_DRV_SPI_BIT_ORDER_MSB_FIRST,
};
err_code = nrf_drv_spi_init(&m_spi_master_0, &config, NULL);
if (err_code != NRF_SUCCESS)
{
// Initialization failed. Take recovery action.
}
}
void u8g_Delay(uint16_t val)
{
nrf_delay_ms(val);
}
void u8g_MicroDelay(void)
{
nrf_delay_us(1);
}
void u8g_10MicroDelay(void)
{
nrf_delay_us(10);
}
uint8_t u8g_com_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr)
{
switch(msg)
{
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
if ( arg_val <= U8G_SPI_CLK_CYCLE_50NS )
{
spi_init(NRF_DRV_SPI_FREQ_8M);
}
else if ( arg_val <= U8G_SPI_CLK_CYCLE_300NS )
{
spi_init(NRF_DRV_SPI_FREQ_4M);
}
else if ( arg_val <= U8G_SPI_CLK_CYCLE_400NS )
{
spi_init(NRF_DRV_SPI_FREQ_2M);
}
else
{
spi_init(NRF_DRV_SPI_FREQ_1M);
}
nrf_gpio_cfg_output(U8G_PIN_SCE);
nrf_gpio_cfg_output(U8G_PIN_DC);
nrf_gpio_cfg_output(U8G_PIN_RST);
u8g_MicroDelay();
break;
case U8G_COM_MSG_ADDRESS:
/* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_10MicroDelay();
nrf_gpio_pin_write(U8G_PIN_DC, arg_val);
u8g_10MicroDelay();
break;
case U8G_COM_MSG_CHIP_SELECT:
if ( arg_val == 0 )
{
/* this delay is required to avoid that the display is switched off too early --> DOGS102 with LPC1114 */
nrf_delay_us(50);
nrf_gpio_pin_write(U8G_PIN_SCE, 1);
}
else
{
/* enable */
nrf_gpio_pin_write(U8G_PIN_SCE, 0);
}
u8g_MicroDelay();
break;
case U8G_COM_MSG_RESET:
nrf_gpio_pin_write(U8G_PIN_RST, arg_val);
u8g_10MicroDelay();
break;
case U8G_COM_MSG_WRITE_BYTE:
nrf_drv_spi_transfer(&m_spi_master_0, &arg_val, 1, NULL, 0);
u8g_MicroDelay();
break;
case U8G_COM_MSG_WRITE_SEQ:
case U8G_COM_MSG_WRITE_SEQ_P:
nrf_drv_spi_transfer(&m_spi_master_0, arg_ptr, arg_val, NULL, 0);
break;
}
return 1;
}

+ 8
- 0
drivers/u8g/u8g_arm.h View File

@ -0,0 +1,8 @@
#ifndef _U8G_ARM_H
#define _U8G_ARM_H
#include "u8g.h"
uint8_t u8g_com_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr);
#endif

+ 7
- 0
platform/delay.mk View File

@ -0,0 +1,7 @@
# Include me in your Makefile to build and add includes
# Don't forget to set a correct ROOT
C_SOURCE_FILES += $(NRF5_SDK)/components/drivers_nrf/delay/nrf_delay.c
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/delay

+ 7
- 0
platform/hal.mk View File

@ -0,0 +1,7 @@
# Include me in your Makefile to build and add includes
# Don't forget to set a correct ROOT
C_SOURCE_FILES +=
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/hal

+ 14
- 0
platform/spi.mk View File

@ -0,0 +1,14 @@
# Include me in your Makefile to build and add includes
# Don't forget to set a correct ROOT
C_SOURCE_FILES += $(NRF5_SDK)/components/drivers_nrf/common/nrf_drv_common.c
C_SOURCE_FILES += $(NRF5_SDK)/components/drivers_nrf/spi_master/nrf_drv_spi.c
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/nrf_soc_nosd
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/config
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/spi_master
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/common
INC_PATHS += -I$(NRF5_SDK)/components/libraries/util

+ 21
- 0
platform/uart.mk View File

@ -0,0 +1,21 @@
# Include me in your Makefile to build and add includes
# Don't forget to set a correct ROOT
C_SOURCE_FILES += $(NRF5_SDK)/components/drivers_nrf/common/nrf_drv_common.c
C_SOURCE_FILES += $(NRF5_SDK)/components/drivers_nrf/uart/nrf_drv_uart.c
C_SOURCE_FILES += $(NRF5_SDK)/components/libraries/uart/app_uart.c
C_SOURCE_FILES += $(NRF5_SDK)/components/libraries/util/app_util_platform.c
C_SOURCE_FILES += $(NRF5_SDK)/components/libraries/util/app_error.c
INC_PATHS += -I$(NRF5_SDK)/components/libraries/uart
INC_PATHS += -I$(NRF5_SDK)/components/libraries/util
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/uart
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/gpiote
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/nrf_soc_nosd/
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/config/
INC_PATHS += -I$(NRF5_SDK)/components/drivers_nrf/common/
#INC_PATHS += -I$(NRF5_SDK)/components/libraries/util

Loading…
Cancel
Save