E32_433开发板程序
This commit is contained in:
1478
Middlewares/MultMenu/application/AirPlane.c
Normal file
1478
Middlewares/MultMenu/application/AirPlane.c
Normal file
File diff suppressed because it is too large
Load Diff
12
Middlewares/MultMenu/application/AirPlane.h
Normal file
12
Middlewares/MultMenu/application/AirPlane.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _AirPlane_H
|
||||
#define _AirPlane_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h> // rand
|
||||
#include "menuConfig.h"
|
||||
|
||||
void AirPlane_Run(xpItem item);
|
||||
|
||||
#endif
|
||||
385
Middlewares/MultMenu/application/DinoGame.c
Normal file
385
Middlewares/MultMenu/application/DinoGame.c
Normal file
@ -0,0 +1,385 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Freescale Semiconductor, Inc.
|
||||
* Copyright 2016-2021 NXP
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
/* Standard C Included Files */
|
||||
#include "DinoGame.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* Definitions
|
||||
******************************************************************************/
|
||||
/* System Tick Configuration */
|
||||
#define SYS_TICK_PER_SECOND 1000
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Prototypes
|
||||
******************************************************************************/
|
||||
|
||||
/*******************************************************************************
|
||||
* Variables
|
||||
******************************************************************************/
|
||||
extern u8g2_t u8g2;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* Code
|
||||
|
||||
******************************************************************************/
|
||||
static int random(int low, int high)
|
||||
{
|
||||
return rand() % (high - low + 1) + low;
|
||||
}
|
||||
|
||||
static unsigned long millis(void)
|
||||
{
|
||||
return ((unsigned long)HAL_GetTick() * 1000 / SYS_TICK_PER_SECOND );
|
||||
}
|
||||
|
||||
// https://github.com/sarafong/T-Rex-Runner/blob/master/TRexRunner/TRexRunner.ino
|
||||
|
||||
//Multiple Dino Bitmaps
|
||||
|
||||
//--------------------Bitmaps--------------------//
|
||||
|
||||
//----------Dimensions----------//
|
||||
#define smallcactus_width 8
|
||||
#define smallcactus_height 17
|
||||
#define standing_width 21
|
||||
#define standing_height 20
|
||||
#define frontLeg_width 21
|
||||
#define frontLeg_height 20
|
||||
#define backLeg_width 21
|
||||
#define backLeg_height 20
|
||||
#define gameover_width 99
|
||||
#define gameover_height 35
|
||||
#define easy_width 32
|
||||
#define easy_height 15
|
||||
#define medium_width 30
|
||||
#define medium_height 20
|
||||
#define hard_width 32
|
||||
#define hard_height 15
|
||||
#define insane_width 30
|
||||
#define insane_height 20
|
||||
#define menu_width 32
|
||||
#define menu_height 15
|
||||
#define replay_width 32
|
||||
#define replay_height 15
|
||||
|
||||
#define UP 3
|
||||
#define DOWN 2
|
||||
|
||||
//----------Bitmap Arrays----------//
|
||||
|
||||
static unsigned char smallcactus_bits[] = {
|
||||
0x18, 0x18, 0x98, 0x98, 0x99, 0x99, 0x99, 0x99, 0x79, 0x19, 0x1e, 0x18,
|
||||
0x18, 0x18, 0x18, 0x18, 0x18 };
|
||||
|
||||
static unsigned char standing_bits[] = {
|
||||
0x00, 0xf8, 0x0f, 0x00, 0xcc, 0x1f, 0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x1f,
|
||||
0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x00, 0x00, 0xf8, 0x07, 0x01, 0x3e, 0x00,
|
||||
0x01, 0x7f, 0x00, 0xc3, 0xff, 0x01, 0xef, 0x7f, 0x00, 0xff, 0x7f, 0x00,
|
||||
0xfe, 0x3f, 0x00, 0xfc, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xf0, 0x07, 0x00,
|
||||
0xe0, 0x0e, 0x00, 0x60, 0x04, 0x00, 0x20, 0x08, 0x00, 0x60, 0x08, 0x00 };
|
||||
|
||||
static unsigned char frontLeg_bits[] = {
|
||||
0x00, 0xf0, 0x0f, 0x00, 0xdc, 0x1f, 0x00, 0xf8, 0x1f, 0x00, 0xf8, 0x1f,
|
||||
0x00, 0xf8, 0x1f, 0x00, 0xfc, 0x00, 0x00, 0xf8, 0x07, 0x01, 0x7e, 0x00,
|
||||
0x01, 0x7f, 0x00, 0xc3, 0xff, 0x01, 0xef, 0x7f, 0x01, 0xff, 0x7f, 0x00,
|
||||
0xfe, 0x7f, 0x00, 0xfc, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xf0, 0x0f, 0x00,
|
||||
0xe0, 0x18, 0x00, 0xe0, 0x00, 0x00, 0x20, 0x00, 0x00, 0x60, 0x00, 0x00 };
|
||||
|
||||
static unsigned char backLeg_bits[] = {
|
||||
0x00, 0xf8, 0x0f, 0x00, 0xd8, 0x1f, 0x00, 0xfc, 0x1f, 0x00, 0xf8, 0x1f,
|
||||
0x00, 0xfc, 0x1f, 0x00, 0xf8, 0x00, 0x00, 0xfc, 0x07, 0x01, 0x3e, 0x00,
|
||||
0x01, 0x7f, 0x00, 0xc3, 0xff, 0x01, 0xef, 0x7f, 0x00, 0xff, 0x7f, 0x00,
|
||||
0xfe, 0x3f, 0x00, 0xfc, 0x3f, 0x00, 0xf8, 0x1f, 0x00, 0xf0, 0x07, 0x00,
|
||||
0x60, 0x0e, 0x00, 0xc0, 0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x0c, 0x00 };
|
||||
|
||||
static unsigned char gameover_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xc0, 0x03, 0x0e, 0xd8, 0xc0, 0x07, 0x80, 0x07, 0x24,
|
||||
0xe0, 0x01, 0x0f, 0x00, 0x20, 0x00, 0x09, 0xf8, 0x40, 0x00, 0x80, 0x04,
|
||||
0x66, 0x30, 0x80, 0x09, 0x00, 0x20, 0x03, 0x19, 0xe8, 0xc0, 0x03, 0x80,
|
||||
0x04, 0x3c, 0xe0, 0x01, 0x0d, 0x00, 0x60, 0x02, 0x1b, 0x88, 0x40, 0x00,
|
||||
0xc0, 0x0c, 0x18, 0x20, 0x00, 0x07, 0x00, 0xc0, 0x03, 0x11, 0x98, 0xc0,
|
||||
0x07, 0x80, 0x07, 0x08, 0xe0, 0x01, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54,
|
||||
0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x7e, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x1e, 0xe6, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x4e, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x6e, 0xef, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xce, 0xef, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xee, 0xef, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xe0, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0xf4, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe,
|
||||
0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xfe, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char easy_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0xc0, 0xf0, 0x00, 0x00, 0xf0, 0x10, 0x00, 0x00, 0xfc,
|
||||
0x50, 0x6d, 0x09, 0xff, 0x10, 0x2c, 0xc5, 0xff, 0x10, 0x4b, 0x06, 0xff,
|
||||
0xf0, 0x7e, 0x02, 0xfc, 0x00, 0x00, 0x02, 0xf0, 0x00, 0x00, 0x00, 0xc0,
|
||||
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char medium_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x22, 0x40, 0x01, 0x00, 0x66, 0x40, 0x00, 0x00,
|
||||
0xaa, 0x75, 0xd5, 0x0f, 0xda, 0x4f, 0x61, 0x08, 0x82, 0x48, 0x45, 0x09,
|
||||
0x42, 0x77, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
|
||||
0x00, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0xf0, 0x01, 0x00,
|
||||
0x00, 0xf8, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0xfc, 0x07, 0x00,
|
||||
0x00, 0xfc, 0x07, 0x00, 0x00, 0xfe, 0x0f, 0x00 };
|
||||
|
||||
static unsigned char hard_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x07, 0x00, 0x00, 0x00, 0x1f, 0x40, 0x00, 0x20, 0x7f, 0x40, 0x04, 0x20,
|
||||
0xff, 0x41, 0xbb, 0x3b, 0xff, 0x43, 0x62, 0x24, 0xff, 0x41, 0x8c, 0x24,
|
||||
0x7f, 0x40, 0xb8, 0x38, 0x1f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char insane_bits[] = {
|
||||
0x00, 0xfe, 0x0f, 0x00, 0x00, 0xfc, 0x07, 0x00, 0x00, 0xfc, 0x07, 0x00,
|
||||
0x00, 0xf8, 0x03, 0x00, 0x00, 0xf8, 0x03, 0x00, 0x00, 0xf0, 0x01, 0x00,
|
||||
0x00, 0xf0, 0x01, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00,
|
||||
0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x18, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0xc0, 0xdd, 0x9d, 0x03,
|
||||
0x50, 0x84, 0xa5, 0x03, 0x50, 0x52, 0x65, 0x00, 0x58, 0xdc, 0xa5, 0x03,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char menu_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x07, 0x00, 0x00, 0x00, 0x1f, 0x10, 0x01, 0x00, 0x7f, 0x30, 0x01, 0x00,
|
||||
0xff, 0xb1, 0xdd, 0x25, 0xff, 0x53, 0x5d, 0x26, 0xff, 0x11, 0x44, 0x4a,
|
||||
0x7f, 0x10, 0x5d, 0x3a, 0x1f, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
static unsigned char replay_bits[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80,
|
||||
0x00, 0x00, 0x00, 0xc0, 0x07, 0x20, 0x00, 0xf0, 0x09, 0x20, 0x00, 0xfc,
|
||||
0xe9, 0xae, 0x4b, 0xff, 0xe7, 0x32, 0xeb, 0xff, 0x15, 0xb2, 0x34, 0xff,
|
||||
0xe9, 0xae, 0x13, 0xfc, 0x00, 0x02, 0x10, 0xf0, 0x00, 0x00, 0x00, 0xc0,
|
||||
0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
|
||||
|
||||
//----------Initializing Variables----------//
|
||||
static unsigned long dinoTimeToMove = 0; //Used to space out time(millis) between draws/moves
|
||||
static unsigned long dinoTimeToDraw = 0;
|
||||
|
||||
static int score;
|
||||
static int highScore = 0;
|
||||
static int multiplier; //Score multiplier
|
||||
|
||||
//bool ignoreRepeat = false; //Avoid Switch Bouncing
|
||||
static long compensation; //To compensate for the amount of time the Arduino has been running for after each run (essentially "resets" the time)
|
||||
static bool gameOver;
|
||||
static bool menu = true;
|
||||
|
||||
static bool down, jump; //Boolean values to check the state of the dinosaur
|
||||
// static int dinoSwitch; //Switch between dino bitmaps to simulate movement
|
||||
static int dinoY, cactiX1, cactiX2; //Positions of objects
|
||||
static int velocity; //Speed of entire game
|
||||
static int difficulty; //How fast the velocity increases
|
||||
|
||||
|
||||
//--------------------Functions--------------------//
|
||||
|
||||
//Set/Reset Loop for Playing Again
|
||||
void reset(){
|
||||
compensation = millis();
|
||||
gameOver = false;
|
||||
down = false;
|
||||
jump = false;
|
||||
// dinoSwitch = true;
|
||||
dinoY = 44;
|
||||
cactiX1 = 130;
|
||||
cactiX2 = cactiX1 + random(70, 120);
|
||||
velocity = 2;
|
||||
}
|
||||
|
||||
//Deteching Joystick Interaction
|
||||
void keyPress(xpItem item)
|
||||
{
|
||||
uint8_t temp;
|
||||
|
||||
if(item->state == MENU_UP)temp = DOWN;
|
||||
if(item->state == MENU_DOWN)temp = UP;
|
||||
if(menu & (temp != 0))
|
||||
{
|
||||
reset();
|
||||
menu = false;
|
||||
if(temp == DOWN)
|
||||
{
|
||||
difficulty = 7500;
|
||||
multiplier = 15000 / difficulty;
|
||||
}
|
||||
if(temp == UP)
|
||||
{
|
||||
difficulty = 2500;
|
||||
multiplier = 15000 / difficulty;
|
||||
}
|
||||
}
|
||||
else if ( gameOver && (temp!=0) ) { //Left -> PlayAgain // Right -> Menu
|
||||
//ignoreRepeat = false;
|
||||
reset();
|
||||
if ( temp == UP ) menu = true; //Pushing Down
|
||||
}
|
||||
else if ( dinoY == 44 && temp == DOWN ) { //Corresponds to pushing up on the joystick
|
||||
jump = true;
|
||||
down = true;
|
||||
}
|
||||
}
|
||||
|
||||
//Collision Detecting and Setting HighScore
|
||||
void collision(void)
|
||||
{
|
||||
if ( cactiX1 <= 23 && cactiX1 + smallcactus_width >= 15 && dinoY+20 >= 50 ) {
|
||||
if ( (millis()-compensation)*multiplier/250 > highScore && !gameOver ) highScore = (millis()-compensation)*multiplier/250; //Changes highscore if current score is greater
|
||||
gameOver = true;
|
||||
}
|
||||
}
|
||||
|
||||
void moveDino(void)
|
||||
{
|
||||
if ( dinoY > 44 ) dinoY = 44; //Resets dinosaur to it passes it
|
||||
if ( jump || dinoY <= 43 ) { //Allows jumping if on the ground
|
||||
jump = false;
|
||||
if ( dinoY >= 16 && down ) dinoY -= velocity; //Going up
|
||||
else { //Going down
|
||||
down = false;
|
||||
dinoY += velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void moveCactus(void)
|
||||
{
|
||||
cactiX1 -= velocity;
|
||||
cactiX2 -= velocity;
|
||||
if ( cactiX1 <= -15 ) { //Once cacti reaches left side of screen, resets to right side of screen
|
||||
cactiX1 = cactiX2;
|
||||
cactiX2 = cactiX1 + random(70, 150);
|
||||
}
|
||||
}
|
||||
|
||||
//-------Move Functions-------//
|
||||
void moveObjects(void)
|
||||
{
|
||||
if( millis() > dinoTimeToMove+50 )
|
||||
{ //Updates every 50 milliseconds
|
||||
velocity = (millis()-compensation)/difficulty + 2; //Increases velocity as game progresses
|
||||
moveDino();
|
||||
moveCactus();
|
||||
dinoTimeToMove = millis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------Draw Functions-------//
|
||||
void drawDinoCactus(void)
|
||||
{
|
||||
if ( dinoY < 44 ) u8g2_DrawXBM(&u8g2, 10, dinoY, standing_width, standing_height, standing_bits); //While jumping don't change bitmap
|
||||
else if ( (millis()-compensation) % 16 > 9 ) u8g2_DrawXBM(&u8g2, 10, dinoY, frontLeg_width, frontLeg_height, frontLeg_bits); //Switch between bitmaps every 9 millis
|
||||
else u8g2_DrawXBM(&u8g2, 10, dinoY, backLeg_width, backLeg_height, backLeg_bits);
|
||||
u8g2_DrawXBM(&u8g2, cactiX1, 47, smallcactus_width, smallcactus_height, smallcactus_bits); //Draw cacti
|
||||
u8g2_DrawXBM(&u8g2, cactiX2, 47, smallcactus_width, smallcactus_height, smallcactus_bits);
|
||||
}
|
||||
|
||||
void drawScore(void)
|
||||
{
|
||||
char scoreBuff[50];
|
||||
if ( menu ) { //Print highscore on menu screen
|
||||
score = highScore;
|
||||
snprintf(scoreBuff, 50, "HighS: %d", score);
|
||||
}
|
||||
else if ( !gameOver )
|
||||
{ //Increments score ONLY while playing
|
||||
score = (millis() - compensation) / 250;
|
||||
snprintf(scoreBuff, 50, "Score: %d", score);
|
||||
}
|
||||
u8g2_SetFont(&u8g2, MENU_FONT);
|
||||
u8g2_DrawStr(&u8g2, 55, 8, scoreBuff );
|
||||
}
|
||||
|
||||
//Draws Game Over Screen
|
||||
void playAgain(void)
|
||||
{
|
||||
u8g2_DrawXBM(&u8g2, 14, 14, gameover_width, gameover_height, gameover_bits);
|
||||
u8g2_DrawXBM(&u8g2, 23, 30, replay_width, replay_height, replay_bits);
|
||||
u8g2_DrawXBM(&u8g2, 70, 30, menu_width, menu_height, menu_bits);
|
||||
}
|
||||
|
||||
//Draws Menu Screen
|
||||
void menuScreen(void)
|
||||
{
|
||||
u8g2_DrawXBM(&u8g2, 26, 30, easy_width, easy_height, easy_bits);
|
||||
u8g2_DrawXBM(&u8g2, 49, 12, medium_width, medium_height, medium_bits);
|
||||
u8g2_DrawXBM(&u8g2, 69, 30, hard_width, hard_height, hard_bits);
|
||||
u8g2_DrawXBM(&u8g2, 49, 43, insane_width, insane_height, insane_bits);
|
||||
}
|
||||
|
||||
void draw_DinoGame(void)
|
||||
{
|
||||
if( millis() > dinoTimeToDraw + 25 ){ //Draws every 25 milliseconds
|
||||
do {
|
||||
drawDinoCactus();
|
||||
drawScore();
|
||||
if ( menu ) menuScreen(); //Draw Menu Screen
|
||||
else if ( gameOver ) playAgain(); //Draw Game Over Screen
|
||||
} while( u8g2_NextPage(&u8g2) );
|
||||
dinoTimeToDraw = millis();
|
||||
}
|
||||
}
|
||||
/*!
|
||||
* @brief DinoGame_Task function
|
||||
*/
|
||||
void DinoGame_Run(xpItem item)
|
||||
{
|
||||
static uint8_t Dino_IntoState=false;
|
||||
if(Dino_IntoState==false)
|
||||
{
|
||||
/* set systick and start systick interrupt */
|
||||
SysTick_Config(SystemCoreClock/SYS_TICK_PER_SECOND);
|
||||
//u8g2_SetFont(&u8g2, u8g2_font_helvB08_tr);
|
||||
u8g2_SetFont(&u8g2, MENU_FONT);
|
||||
u8g2_SetFontDirection(&u8g2, 0);
|
||||
u8g2_SetFontRefHeightAll(&u8g2);
|
||||
reset();
|
||||
Dino_IntoState=true;
|
||||
}
|
||||
|
||||
u8g2_FirstPage(&u8g2);
|
||||
keyPress(item);
|
||||
if ( (!gameOver) && (!menu) )
|
||||
{
|
||||
moveObjects();
|
||||
}
|
||||
draw_DinoGame();
|
||||
collision();
|
||||
}
|
||||
12
Middlewares/MultMenu/application/DinoGame.h
Normal file
12
Middlewares/MultMenu/application/DinoGame.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef _DinoGame_H
|
||||
#define _DinoGame_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h> // rand
|
||||
#include "application.h"
|
||||
|
||||
void DinoGame_Run(xpItem item);
|
||||
|
||||
#endif
|
||||
799
Middlewares/MultMenu/application/application.c
Normal file
799
Middlewares/MultMenu/application/application.c
Normal file
@ -0,0 +1,799 @@
|
||||
#include "application.h"
|
||||
#include "dispDirver.h"
|
||||
#include "main.h"
|
||||
#include "e32_hal.h"
|
||||
#include "usart.h"
|
||||
|
||||
/**
|
||||
* 菜单 Setting > Work Mode 对应的工作模式显示名称
|
||||
*/
|
||||
static const char *mode_name[4] = {"Transparent","WOR Master ","WOR Slave ","Sleep "};
|
||||
|
||||
/**
|
||||
* 菜单 Setting > Rate Mode 对应的空速显示名称
|
||||
*/
|
||||
static const char *rate_name[8] = {" 2.4"," 2.4"," 2.4"," 4.8"," 9.6","19.2","19.2","19.2"};
|
||||
|
||||
/**
|
||||
* 菜单 Setting > 参数默认显示值
|
||||
*/
|
||||
menu_config_t user_config =
|
||||
{
|
||||
.work_mode = 3, // 工作模式
|
||||
.rate_mode = 2, // 空速模式 挡位选择
|
||||
.channel = 23, // 通信信道
|
||||
.tx_power = 30, // 发射功率 挡位选择
|
||||
.tx_count = 10, // 数据发送测试总次数
|
||||
};
|
||||
|
||||
/**
|
||||
* 注意为xbm格式数据 可以使用网络在线工具转换 https://convertio.co/zh/xbm-converter/
|
||||
*/
|
||||
static const unsigned char ebyte_logo[861] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
|
||||
0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x70, 0x00, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00,
|
||||
0x00, 0x00, 0x00, 0xE0, 0x00, 0x00, 0x80, 0x9C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x06, 0x18, 0x00, 0x00, 0x60, 0xC0, 0x01, 0x00, 0xC0, 0x26, 0x01,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x0C, 0x00, 0x00, 0x60, 0x80, 0x01, 0x00,
|
||||
0x40, 0x26, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x06, 0x00, 0x00, 0xC0,
|
||||
0x00, 0x03, 0x00, 0x40, 0x1E, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x03,
|
||||
0x03, 0x80, 0x81, 0x01, 0x07, 0x00, 0x40, 0x16, 0x01, 0x00, 0x00, 0x00,
|
||||
0xC0, 0x80, 0x83, 0x03, 0x80, 0x03, 0x03, 0x06, 0x00, 0xC0, 0x36, 0x01,
|
||||
0x00, 0x00, 0x00, 0x60, 0xC0, 0xC1, 0x01, 0x00, 0x07, 0x07, 0x0C, 0x00,
|
||||
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0xC0, 0x00, 0x00, 0x06,
|
||||
0x06, 0x0C, 0x00, 0x00, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x60,
|
||||
0xC0, 0x07, 0x0C, 0x06, 0x0C, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0x00,
|
||||
0x60, 0xC0, 0x60, 0xC0, 0x0F, 0x0C, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x30, 0x60, 0x60, 0xE0, 0x0F, 0x08, 0x0C, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0x20, 0xE0, 0x0F, 0x18,
|
||||
0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x60, 0x20,
|
||||
0xE0, 0x0F, 0x18, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x30, 0x60, 0x60, 0xC0, 0x0F, 0x18, 0x0C, 0x18, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x20, 0x40, 0x60, 0x80, 0x03, 0x0C, 0x0C, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0x60, 0x00, 0x00, 0x0C,
|
||||
0x06, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xC0, 0xC0,
|
||||
0x00, 0x00, 0x06, 0x06, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x60, 0x80, 0xC1, 0x01, 0x00, 0x06, 0x07, 0x0C, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0x80, 0x83, 0x03, 0x80, 0x03, 0x03, 0x0E, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x01, 0x03, 0x03, 0x80, 0x81,
|
||||
0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x06,
|
||||
0xC0, 0x07, 0xC0, 0x01, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x03, 0x0C, 0xC0, 0x07, 0xE0, 0x80, 0x03, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0xC0, 0x07, 0x00, 0x80, 0x01, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E, 0x00, 0xC0, 0x07, 0x00,
|
||||
0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x00,
|
||||
0xC0, 0x07, 0x00, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0F, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x0F, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xC0, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xFF, 0xFF, 0xE7, 0xFF, 0x3F, 0xF0, 0x03, 0xE0, 0xCF, 0xFF, 0xFF, 0xCF,
|
||||
0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xE7, 0xFF, 0xFF, 0xE0, 0x07, 0xE0, 0xC7,
|
||||
0xFF, 0xFF, 0xCF, 0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0xC1,
|
||||
0x0F, 0xF0, 0xC3, 0xFF, 0xFF, 0xCF, 0xFF, 0xFF, 0x01, 0x3F, 0x00, 0xC0,
|
||||
0x07, 0xF8, 0xC3, 0x0F, 0xF8, 0x01, 0xC0, 0x0F, 0xC0, 0x0F, 0x00, 0x00,
|
||||
0x1F, 0x00, 0xC0, 0x07, 0xF0, 0x83, 0x1F, 0xFC, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0x07, 0x00, 0x00, 0x3F, 0x00, 0xC0, 0x07, 0xF0, 0x01, 0x3F, 0x7E, 0x00,
|
||||
0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0x3F, 0x00, 0xE0, 0x07, 0xFC, 0x00,
|
||||
0x7E, 0x3E, 0x00, 0xC0, 0x0F, 0xC0, 0x0F, 0x00, 0x00, 0xFF, 0xFF, 0xC3,
|
||||
0xFF, 0x3F, 0x00, 0xFC, 0x1F, 0x00, 0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x00,
|
||||
0xFF, 0xFF, 0xC3, 0xFF, 0x3F, 0x00, 0xF8, 0x0F, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xC3, 0xFF, 0xFF, 0x01, 0xF0, 0x07, 0x00,
|
||||
0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x00, 0x3F, 0x00, 0xC0, 0x07, 0xF0, 0x03,
|
||||
0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0x3F, 0x00, 0xC0,
|
||||
0x07, 0xE0, 0x03, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00,
|
||||
0x3F, 0x00, 0xE0, 0x07, 0xE0, 0x07, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0x07, 0x00, 0x00, 0x3F, 0x00, 0xC0, 0x07, 0xF0, 0x03, 0xE0, 0x03, 0x00,
|
||||
0xC0, 0x0F, 0xC0, 0x07, 0x00, 0x00, 0xFF, 0xFF, 0xC7, 0xFF, 0xFF, 0x03,
|
||||
0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x01, 0xFF, 0xFF, 0xC7,
|
||||
0xFF, 0xFF, 0x01, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0, 0xFF, 0xFF, 0x01,
|
||||
0xFF, 0xFF, 0xC7, 0xFF, 0x7F, 0x00, 0xE0, 0x03, 0x00, 0xC0, 0x0F, 0xC0,
|
||||
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, };
|
||||
|
||||
/**
|
||||
* Tx Mode 数据发送测试 过程状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
TX_MODE_INIT = 0,
|
||||
TX_MODE_SEND,
|
||||
TX_MODE_WAIT,
|
||||
TX_MODE_END,
|
||||
}tx_state_t;
|
||||
|
||||
/**
|
||||
* Rx Mode 数据接收测试 过程状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
RX_MODE_INIT = 0,
|
||||
RX_MODE_RECV,
|
||||
RX_MODE_WAIT,
|
||||
RX_MODE_END,
|
||||
}rx_state_t;
|
||||
|
||||
/**
|
||||
* Rx Mode 数据接收测试 提示光标状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
HINT_WAIT = 0,
|
||||
HINT_DONE,
|
||||
}hint_state_t;
|
||||
|
||||
/**
|
||||
* Version 版本信息显示 过程状态
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
VERSION_START = 0,
|
||||
VERSION_WAIT,
|
||||
VERSION_END
|
||||
}version_state_t;
|
||||
|
||||
/**
|
||||
* @brief 菜单 进入首页
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void logo_callback( xpItem item )
|
||||
{
|
||||
OLED_ClearBuffer();
|
||||
OLED_DrawXBMP(4, 6, 118, 57, ebyte_logo);
|
||||
OLED_SendBuffer();
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
case MENU_DOWN:
|
||||
item->state = MENU_ENTER;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组工作模式设定 Setting > Work Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void work_mode_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 0;
|
||||
int scrollbar_max = 3;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 1, (*item->data.ptr));
|
||||
e32_hal_work_mode( (work_mode_t)(*item->data.ptr) );
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, -1, (*item->data.ptr));
|
||||
e32_hal_work_mode( (work_mode_t)(*item->data.ptr) );
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Mode: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
sprintf(value, "%s", mode_name[(*item->data.ptr)]);
|
||||
OLED_DrawStr(8, 40, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组通信空速设定 Setting > Rate Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void rate_mode_callback( xpItem item )
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 2;
|
||||
int scrollbar_max = 5;
|
||||
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 1, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, -1, (*item->data.ptr));
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Rate: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
|
||||
sprintf(value, "%s Kbps", rate_name[(*item->data.ptr)]);
|
||||
OLED_DrawStr(8, 40, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组通信信道设定 Setting > Channel
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void channel_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 0;
|
||||
int scrollbar_max = 41;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 1, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, -1, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
key_set_continue( KEY_NAME_UP, false );
|
||||
key_set_continue( KEY_NAME_DOWN, false );
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 50, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
key_set_continue( KEY_NAME_UP, true );
|
||||
key_set_continue( KEY_NAME_DOWN, true );
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Channel: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
|
||||
sprintf(value, "%d MHz", ((*item->data.ptr) + 410 ));
|
||||
OLED_DrawStr(8, 40, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组发射功率设定 Setting > TX Power
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void tx_power_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int power_convert[4] = { 30, 27, 24, 21 };
|
||||
int scrollbar_min = 0;
|
||||
int scrollbar_max = 3;
|
||||
|
||||
/* 默认对应 power_convert 中的 30 */
|
||||
static int scrollbar_value = 0;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
scrollbar_value = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 1, scrollbar_value);
|
||||
(*item->data.ptr) = power_convert[ scrollbar_value ];
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
scrollbar_value = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, -1, scrollbar_value);
|
||||
(*item->data.ptr) = power_convert[ scrollbar_value ];
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 0, scrollbar_value);
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Power: %d dBm", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 模组通信测试数据发射次数设定 Setting > TX Count
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void tx_count_callback( xpItem item)
|
||||
{
|
||||
char value[20] = {0};
|
||||
int scrollbar_min = 10;
|
||||
int scrollbar_max = 100;
|
||||
|
||||
if (DialogScale_Show(0, 0, 127, 63))
|
||||
{
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 10, (*item->data.ptr));
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
(*item->data.ptr) = Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, -10, (*item->data.ptr));
|
||||
break;
|
||||
default:
|
||||
Draw_Scrollbar(8, 30, 111, 6, 0, scrollbar_min, scrollbar_max, 0, (*item->data.ptr));
|
||||
break;
|
||||
}
|
||||
|
||||
sprintf(value, "Count: %d ", (*item->data.ptr));
|
||||
OLED_DrawStr(8, 25, value);
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单三级页面 显示背景色设定 Setting > Back Color
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void background_color_callback( xpItem item )
|
||||
{
|
||||
Set_BgColor(item->switchState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Mode 数据发送测试 构造发送数据
|
||||
*
|
||||
* @param send_count 当前发送计数
|
||||
*/
|
||||
static void tx_e32_send( int send_count )
|
||||
{
|
||||
char value[30] = {0};
|
||||
uint8_t tx_length = 0;
|
||||
|
||||
gpio_led_tx_on();
|
||||
|
||||
tx_length = sprintf( value, "TX.%03d.%03d.", user_config.tx_count , send_count );
|
||||
e32_demo_transmit( (uint8_t*)value , tx_length + 1);
|
||||
|
||||
///@note 此时并不代表已发送完成
|
||||
gpio_led_tx_off();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tx Mode 数据发送测试 发送过程显示
|
||||
*
|
||||
* @param send_count 当前发送计数
|
||||
*/
|
||||
static void tx_display_count( int send_count )
|
||||
{
|
||||
char value[30] = {0};
|
||||
uint8_t bg_color;
|
||||
|
||||
|
||||
/* 如果进入页面后第一次 则刷新全部显示信息 */
|
||||
if( send_count == 0 )
|
||||
{
|
||||
/* display refresh */
|
||||
bg_color = Get_BgColor();
|
||||
|
||||
OLED_ClearBuffer();
|
||||
OLED_SetDrawColor(bg_color);
|
||||
OLED_DrawBox(0, 0, 128, 64);
|
||||
OLED_SetDrawColor(bg_color^0x01);
|
||||
|
||||
sprintf(value, "Channel:%d %dMHz ",user_config.channel,(user_config.channel+410));
|
||||
OLED_DrawStr(0, Font_Size*1, value );
|
||||
|
||||
OLED_DrawLine(0, Font_Size*1+3,127,Font_Size*1+3 );
|
||||
|
||||
sprintf(value, "Rate:%sK Pwr:%ddBm", rate_name[user_config.rate_mode] ,user_config.tx_power);
|
||||
OLED_DrawStr(0, Font_Size*2+3, value);
|
||||
|
||||
OLED_DrawLine(0, Font_Size*2+6,127,Font_Size*2+6 );
|
||||
|
||||
|
||||
sprintf(value, "Tx Total :%d", user_config.tx_count);
|
||||
OLED_DrawStr(0, Font_Size*3+9, value);
|
||||
}
|
||||
|
||||
/* 如果是最后一次发送 */
|
||||
if( send_count == user_config.tx_count )
|
||||
{
|
||||
OLED_DrawStr(0, Font_Size*3+9, "Tx Done ! ");
|
||||
OLED_DrawStr(0, Font_Size*4+9, "Press DOWN button");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(value, "Tx Number:%d", send_count);
|
||||
OLED_DrawStr(0, Font_Size*4+9, value);
|
||||
}
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 模组发送测试 Tx Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void tx_mode_callback( xpItem item )
|
||||
{
|
||||
current_feature = FUNC_FEATURE2;
|
||||
static uint32_t send_count = 0; // 改为uint32_t防止溢出
|
||||
static tx_state_t tx_state = TX_MODE_END;
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
/* 按下DOWN键,触发一次发送 */
|
||||
if( tx_state == TX_MODE_SEND || tx_state == TX_MODE_WAIT )
|
||||
{
|
||||
send_count++;
|
||||
tx_display_count( send_count );
|
||||
tx_e32_send(send_count);
|
||||
}
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
/* 结束 */
|
||||
tx_state = TX_MODE_END;
|
||||
|
||||
break;
|
||||
default:
|
||||
/* 开始 */
|
||||
if( tx_state == TX_MODE_END )
|
||||
{
|
||||
tx_state = TX_MODE_INIT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch( tx_state )
|
||||
{
|
||||
case TX_MODE_INIT:
|
||||
tx_display_count( 0 );
|
||||
e32_demo_menu_config( &user_config );
|
||||
send_count = 0;
|
||||
tx_display_count( send_count );
|
||||
tx_state = TX_MODE_SEND;
|
||||
break;
|
||||
|
||||
case TX_MODE_SEND:
|
||||
/* 等待用户按键触发发送,不再自动发送 */
|
||||
break;
|
||||
|
||||
case TX_MODE_WAIT:
|
||||
/* 等待用户按键 */
|
||||
break;
|
||||
|
||||
case TX_MODE_END:
|
||||
current_feature = FUNC_FEATURE1;
|
||||
default:
|
||||
tx_state = TX_MODE_END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 显示页面初始化
|
||||
*/
|
||||
static void rx_init_display(void)
|
||||
{
|
||||
char value[30] = {0};
|
||||
uint8_t bg_color;
|
||||
|
||||
bg_color = Get_BgColor();
|
||||
|
||||
OLED_ClearBuffer();
|
||||
OLED_SetDrawColor(bg_color);
|
||||
OLED_DrawBox(0, 0, 128, 64);
|
||||
OLED_SetDrawColor(bg_color^0x01);
|
||||
|
||||
sprintf(value, "Channel:%d %dMHz ",user_config.channel,(user_config.channel+410));
|
||||
OLED_DrawStr(0, Font_Size*1, value);
|
||||
|
||||
OLED_DrawLine(0, Font_Size*1+3,127,Font_Size*1+3 );
|
||||
|
||||
sprintf(value, "Rate:%sK",rate_name[user_config.rate_mode] );
|
||||
OLED_DrawStr(0, Font_Size*2+3, value );
|
||||
|
||||
OLED_DrawLine(0, Font_Size*2+6,127,Font_Size*2+6 );
|
||||
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 提示光标显示
|
||||
*
|
||||
* @param state 光标状态
|
||||
*/
|
||||
static void rx_hint( hint_state_t state )
|
||||
{
|
||||
static uint8_t hint_select = 0;
|
||||
static const char *hint[3]={"= ","== ","==="};
|
||||
|
||||
switch( state )
|
||||
{
|
||||
case HINT_WAIT:
|
||||
OLED_DrawStr(100, Font_Size*2+3, hint[hint_select++] );
|
||||
if(hint_select>2)
|
||||
{
|
||||
hint_select = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case HINT_DONE:
|
||||
OLED_DrawStr(100, Font_Size*2+3, "DONE" );
|
||||
break;
|
||||
}
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 无线数据包校验与数据解析
|
||||
*
|
||||
* @param buffer 执行接收数据缓存
|
||||
* @param length 接收数据长度
|
||||
* @param total_number 发送总数
|
||||
* @param current_number 当前包序号
|
||||
* @param rssi 数据包RSSI
|
||||
*/
|
||||
static bool rx_analysis( uint8_t *buffer , uint8_t length , uint32_t *total_number, uint32_t *current_number )
|
||||
{
|
||||
/* 长度至少10字节 */
|
||||
if( length < 10 )
|
||||
return false;
|
||||
|
||||
/* 帧头字符判断TX */
|
||||
if( buffer[0] != 'T' || buffer[1] != 'X' )
|
||||
return false;
|
||||
|
||||
/* 拆分出发送总计数与当前序号 */
|
||||
sscanf( ( char* )(buffer+3), "%d.%d.", total_number, current_number );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Rx Mode 数据接收测试 接收过程显示
|
||||
*
|
||||
* @param total_number 发送总数
|
||||
* @param current_number 但钱
|
||||
* @param rssi 数据包RSSI
|
||||
* @param lost_nubmer 已丢失数据包计数
|
||||
* @param lost_percent 已丢失数据包百分比
|
||||
*/
|
||||
static void rx_mode_display( uint32_t total_number , uint32_t current_number , uint32_t lost_nubmer , uint32_t lost_percent)
|
||||
{
|
||||
char value[30] = {0};
|
||||
|
||||
sprintf(value, "Total:%d ", total_number);
|
||||
OLED_DrawStr(0, Font_Size*3+5, value);
|
||||
|
||||
sprintf(value, "Current:%d ", current_number);
|
||||
OLED_DrawStr(60, Font_Size*3+5, value);
|
||||
|
||||
sprintf(value, "Lost :%d ", lost_nubmer);
|
||||
OLED_DrawStr(0, Font_Size*4+4, value);
|
||||
|
||||
sprintf(value, "Lost P%%:%d%% ", lost_percent);
|
||||
OLED_DrawStr(60, Font_Size*4+4, value);
|
||||
|
||||
OLED_SendBuffer();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 模组通信测试数据发射次数设定 Rx Mode
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void rx_mode_callback( xpItem item )
|
||||
{
|
||||
current_feature = FUNC_FEATURE2;
|
||||
static uint8_t rx_mode_buffer[255];
|
||||
static uint32_t rx_mode_length = 0;
|
||||
static rx_state_t rx_state = RX_MODE_INIT;
|
||||
static uint32_t tick_start;
|
||||
static uint32_t tx_number_record = 0;
|
||||
static uint32_t tx_total_number = 0;
|
||||
static uint32_t rx_count = 0; // 改为uint32_t防止溢出
|
||||
uint32_t tx_current_number = 0;
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
/* 再次开始 */
|
||||
if( rx_state == RX_MODE_WAIT )
|
||||
{
|
||||
rx_state = RX_MODE_INIT;
|
||||
}
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
/* 结束 */
|
||||
rx_state = RX_MODE_END;
|
||||
|
||||
break;
|
||||
default:
|
||||
/* 开始 */
|
||||
if( rx_state == RX_MODE_END )
|
||||
{
|
||||
rx_state = RX_MODE_INIT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch( rx_state )
|
||||
{
|
||||
case RX_MODE_INIT:
|
||||
rx_init_display();
|
||||
e32_demo_menu_config( &user_config );
|
||||
tick_start = HAL_GetTick();
|
||||
rx_count = 0;
|
||||
tx_number_record = 0;
|
||||
rx_state = RX_MODE_RECV;
|
||||
break;
|
||||
|
||||
case RX_MODE_RECV:
|
||||
if( uart1_check_rx_done(rx_mode_buffer, &rx_mode_length) == true)
|
||||
{
|
||||
if( rx_analysis( rx_mode_buffer , rx_mode_length , &tx_total_number, &tx_current_number ) == true )
|
||||
{
|
||||
gpio_led_rx_on();
|
||||
|
||||
/* 其他情况,可能是发送端重新开始了,需要重新计数 */
|
||||
if( tx_number_record >= tx_current_number)
|
||||
{
|
||||
rx_count = 0;
|
||||
}
|
||||
|
||||
tx_number_record = tx_current_number;
|
||||
|
||||
/* 有效接收计数 */
|
||||
rx_count++;
|
||||
|
||||
rx_mode_display(tx_total_number,tx_current_number,(tx_number_record-rx_count), ((tx_number_record-rx_count)*100/tx_number_record));
|
||||
|
||||
// 注释掉自动完成判断,持续接收
|
||||
// if( tx_current_number == tx_total_number )
|
||||
// {
|
||||
// rx_state = RX_MODE_WAIT;
|
||||
// rx_hint( HINT_DONE );
|
||||
// }
|
||||
|
||||
gpio_led_rx_off();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if( (HAL_GetTick() - tick_start) > 1000 )
|
||||
{
|
||||
tick_start = HAL_GetTick();
|
||||
rx_hint( HINT_WAIT );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case RX_MODE_WAIT:
|
||||
/* 接收完成,等待用户按键 */
|
||||
break;
|
||||
|
||||
case RX_MODE_END:
|
||||
current_feature = FUNC_FEATURE1;
|
||||
default:
|
||||
rx_state = RX_MODE_END;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 版本信息显示 Version
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void version_callback( xpItem item )
|
||||
{
|
||||
current_feature = FUNC_FEATURE2;
|
||||
char e32_buffer[30] = {0};
|
||||
uint8_t opt_length = 0;
|
||||
static version_state_t version_state = VERSION_END;
|
||||
uint8_t bg_color;
|
||||
|
||||
switch (item->state)
|
||||
{
|
||||
case MENU_UP:
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
/* 离开 */
|
||||
version_state = VERSION_END;
|
||||
break;
|
||||
default:
|
||||
/* 进入 */
|
||||
if( version_state == VERSION_END )
|
||||
{
|
||||
version_state = VERSION_START;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch( version_state )
|
||||
{
|
||||
case VERSION_START:
|
||||
bg_color = Get_BgColor();
|
||||
|
||||
OLED_ClearBuffer();
|
||||
OLED_SetDrawColor(bg_color);
|
||||
OLED_DrawBox(0, 0, 128, 64);
|
||||
OLED_SendBuffer();
|
||||
|
||||
OLED_SetDrawColor(bg_color^0x01);
|
||||
OLED_DrawStr(0, Font_Size*1, "Model Type:");
|
||||
|
||||
e32_demo_read_device_name( e32_buffer , &opt_length );
|
||||
OLED_DrawStr(8, Font_Size*2, e32_buffer + 8);
|
||||
OLED_DrawLine(0, Font_Size*2+3,127,Font_Size*2+3 );
|
||||
|
||||
OLED_DrawStr(0, Font_Size*3+3, "Model Fireware:");
|
||||
e32_demo_read_fireware_version( e32_buffer , &opt_length );
|
||||
OLED_DrawStr(8, Font_Size*4+3, e32_buffer + 7);
|
||||
OLED_DrawLine(0, Font_Size*4+6,127,Font_Size*4+6 );
|
||||
|
||||
OLED_SendBuffer();
|
||||
|
||||
version_state = VERSION_WAIT;
|
||||
break;
|
||||
|
||||
case VERSION_WAIT:
|
||||
case VERSION_END:
|
||||
current_feature = FUNC_FEATURE1;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 菜单二级页面 重启复位
|
||||
*
|
||||
* @param item 指向项目状态的指针
|
||||
*/
|
||||
void reset_callback( xpItem item )
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
32
Middlewares/MultMenu/application/application.h
Normal file
32
Middlewares/MultMenu/application/application.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef _APPLICATION_H
|
||||
#define _APPLICATION_H
|
||||
|
||||
#include "menu.h"
|
||||
#include "menuConfig.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int work_mode;
|
||||
int rate_mode;
|
||||
int channel;
|
||||
int tx_power;
|
||||
int tx_count;
|
||||
}menu_config_t;
|
||||
|
||||
extern menu_config_t user_config;
|
||||
|
||||
void logo_callback( xpItem item );
|
||||
|
||||
void work_mode_callback( xpItem item );
|
||||
void rate_mode_callback( xpItem item );
|
||||
void channel_callback( xpItem item );
|
||||
void tx_power_callback( xpItem item);
|
||||
void tx_count_callback( xpItem item);
|
||||
void background_color_callback( xpItem item );
|
||||
|
||||
void tx_mode_callback( xpItem item );
|
||||
void rx_mode_callback( xpItem item );
|
||||
void version_callback( xpItem item );
|
||||
void reset_callback( xpItem item );
|
||||
|
||||
#endif
|
||||
281
Middlewares/MultMenu/disp/dispDirver.c
Normal file
281
Middlewares/MultMenu/disp/dispDirver.c
Normal file
@ -0,0 +1,281 @@
|
||||
#include "dispDirver.h"
|
||||
#include "u8g2.h"
|
||||
#include "u8g2_hal.h"
|
||||
#include "menuConfig.h"
|
||||
|
||||
u8g2_t u8g2;
|
||||
|
||||
/**
|
||||
* 初始化显示设备。
|
||||
* 该函数负责初始化OLED显示器,并设置默认字体。
|
||||
*
|
||||
* @无参数
|
||||
* @无返回值
|
||||
*/
|
||||
void Disp_Init(void)
|
||||
{
|
||||
// 初始化U8g2库,为OLED显示做准备
|
||||
u8g2Init(&u8g2);
|
||||
// 设置默认使用的字体为MENU_FONT
|
||||
OLED_SetFont(MENU_FONT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除OLED显示缓冲区
|
||||
*
|
||||
* 该函数用于清空OLED显示器的缓冲区,为新的显示内容做准备。
|
||||
*
|
||||
* 参数:
|
||||
* 无
|
||||
*
|
||||
* 返回值:
|
||||
* 无
|
||||
*/
|
||||
void OLED_ClearBuffer(void)
|
||||
{
|
||||
u8g2_ClearBuffer(&u8g2); // 清除OLED显示缓冲区的具体实现,使用u8g2库提供的函数。
|
||||
}
|
||||
|
||||
/**
|
||||
* 向OLED发送缓冲区数据
|
||||
* 该函数无参数。
|
||||
* 该函数无返回值。
|
||||
*/
|
||||
void OLED_SendBuffer(void)
|
||||
{
|
||||
/* 将U8G2实例的缓冲区数据发送到OLED设备 */
|
||||
u8g2_SendBuffer(&u8g2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取字符串在OLED显示设备上的宽度。
|
||||
*
|
||||
* @param s 指向要测量的字符串的指针。
|
||||
* @return 返回字符串在OLED显示设备上的宽度,单位为像素。
|
||||
*/
|
||||
uint16_t OLED_GetStrWidth(const char *s)
|
||||
{
|
||||
// 调用u8g2库的函数,获取字符串s的宽度
|
||||
return u8g2_GetStrWidth(&u8g2, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置OLED的最大剪辑窗口
|
||||
* 该函数无参数。
|
||||
* 该函数无返回值。
|
||||
*/
|
||||
void OLED_SetMaxClipWindow(void)
|
||||
{
|
||||
u8g2_SetMaxClipWindow(&u8g2); // 调用u8g2库的函数设置最大的剪辑窗口
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置OLED显示器的字体。
|
||||
*
|
||||
* @param font 指向要使用的字体的指针。该字体必须是提前定义并可用的。
|
||||
*
|
||||
* 说明:这个函数通过调用u8g2的设置函数,来更改当前OLED显示的字体。
|
||||
*/
|
||||
void OLED_SetFont(const uint8_t *font)
|
||||
{
|
||||
u8g2_SetFont(&u8g2, font); // 设置U8g2实例的字体
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED屏幕上绘制一个像素点
|
||||
*
|
||||
* @param x 像素点的x坐标
|
||||
* @param y 像素点的y坐标
|
||||
*
|
||||
* 该函数调用u8g2的DrawPixel函数,来在指定位置绘制一个像素点。
|
||||
*/
|
||||
void OLED_DrawPixel(uint16_t x, uint16_t y)
|
||||
{
|
||||
u8g2_DrawPixel(&u8g2, x, y); // 调用u8g2库的绘制像素点函数
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED显示器上绘制一条线。
|
||||
*
|
||||
* @param x1 起始点的X坐标。
|
||||
* @param y1 起始点的Y坐标。
|
||||
* @param x2 终点的X坐标。
|
||||
* @param y2 终点的Y坐标。
|
||||
*
|
||||
* 该函数调用u8g2的DrawLine函数,使用给定的起始点和终点坐标在OLED显示器上绘制一条线。
|
||||
*/
|
||||
void OLED_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
|
||||
{
|
||||
u8g2_DrawLine(&u8g2, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED屏幕上绘制字符串
|
||||
*
|
||||
* @param x 字符串起始绘制的x坐标
|
||||
* @param y 字符串起始绘制的y坐标
|
||||
* @param str 要绘制的字符串
|
||||
* @return 绘制后的光标位置(一般为字符串的结束位置),具体返回值意义可能依赖于u8g2库的实现
|
||||
*/
|
||||
uint16_t OLED_DrawStr(uint16_t x, uint16_t y, const char *str)
|
||||
{
|
||||
// 调用u8g2库的DrawStr函数,在指定位置绘制字符串
|
||||
return u8g2_DrawStr(&u8g2, x, y, str);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置OLED显示设备的绘制颜色。
|
||||
*
|
||||
* @param color 指定的绘制颜色,使用uint8_t类型表示。颜色的具体编码取决于OLED驱动库的实现。
|
||||
*
|
||||
* 该函数通过调用u8g2库的u8g2_SetDrawColor函数,来设置当前绘制的颜色。绘制颜色会影响后续所有绘制操作。
|
||||
*/
|
||||
void OLED_SetDrawColor(uint8_t color)
|
||||
{
|
||||
u8g2_SetDrawColor(&u8g2, color); // 调用u8g2库的函数设置绘制颜色
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED屏幕上绘制一个框架。
|
||||
*
|
||||
* @param x 框架的起始x坐标。
|
||||
* @param y 框架的起始y坐标。
|
||||
* @param w 框架的宽度。
|
||||
* @param h 框架的高度。
|
||||
*
|
||||
* 该函数调用u8g2的绘制框架函数,用于在指定位置和尺寸上绘制一个框架。
|
||||
*/
|
||||
void OLED_DrawFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
|
||||
{
|
||||
u8g2_DrawFrame(&u8g2, x, y, w, h);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED屏幕上绘制一个矩形边框。
|
||||
*
|
||||
* @param x 矩形左上角x坐标。
|
||||
* @param y 矩形左上角y坐标。
|
||||
* @param w 矩形的宽度。
|
||||
* @param h 矩形的高度。
|
||||
* @param r 矩形圆角的半径。
|
||||
*
|
||||
* 该函数调用u8g2的绘制函数,用于在指定位置以指定尺寸和圆角半径绘制一个矩形边框。
|
||||
*/
|
||||
void OLED_DrawRFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r)
|
||||
{
|
||||
u8g2_DrawRFrame(&u8g2, x, y, w, h, r);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED显示器上绘制一个矩形框。
|
||||
*
|
||||
* @param x 矩形框左上角的x坐标。
|
||||
* @param y 矩形框左上角的y坐标。
|
||||
* @param w 矩形框的宽度。
|
||||
* @param h 矩形框的高度。
|
||||
*
|
||||
* 该函数调用u8g2的绘制矩形框函数,传入指定的坐标和尺寸,在OLED屏幕上绘制矩形。
|
||||
*/
|
||||
void OLED_DrawBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h)
|
||||
{
|
||||
u8g2_DrawBox(&u8g2, x, y, w, h); // 调用u8g2库的绘制矩形函数
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED显示器上绘制一个带圆角的矩形。
|
||||
*
|
||||
* @param x 矩形左上角的x坐标。
|
||||
* @param y 矩形左上角的y坐标。
|
||||
* @param w 矩形的宽度。
|
||||
* @param h 矩形的高度。
|
||||
* @param r 矩形圆角的半径。
|
||||
*
|
||||
* 该函数调用u8g2的绘制函数,以指定的坐标和尺寸,在OLED显示器上绘制一个带圆角的矩形。
|
||||
*/
|
||||
void OLED_DrawRBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r)
|
||||
{
|
||||
u8g2_DrawRBox(&u8g2, x, y, w, h, r);
|
||||
}
|
||||
|
||||
/**
|
||||
* 在OLED显示器上绘制一个XBM图像。
|
||||
*
|
||||
* @param x 图像在显示器上的起始x坐标。
|
||||
* @param y 图像在显示器上的起始y坐标。
|
||||
* @param w 图像的宽度。
|
||||
* @param h 图像的高度。
|
||||
* @param bitmap 指向包含XBM图像数据的缓冲区的指针。
|
||||
*
|
||||
* 此函数使用u8g2库的u8g2_DrawXBMP函数来绘制图像。图像数据必须是XBM格式的。
|
||||
*/
|
||||
void OLED_DrawXBMP(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_DrawXBMP(&u8g2, x, y, w, h, bitmap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置OLED显示器的对比度。
|
||||
*
|
||||
* @param value 对比度值,有效范围通常为0到255,具体取决于硬件的限制。
|
||||
*
|
||||
* 该函数通过调用u8g2库中的u8g2_SetContrast函数,来设置OLED显示器的对比度。
|
||||
* 使用者需要根据具体的OLED显示器和u8g2配置来选择合适的对比度值。
|
||||
*/
|
||||
void OLED_SetContrast(uint8_t value)
|
||||
{
|
||||
u8g2_SetContrast(&u8g2, value); // 调用u8g2库函数设置对比度
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置OLED电源节省模式
|
||||
*
|
||||
* 本函数用于根据输入参数启用或禁用OLED的电源节省模式。当is_enable为1时,启用电源节省模式;
|
||||
* 当is_enable为0时,禁用电源节省模式。
|
||||
*
|
||||
* @param is_enable 一个无符号字符(uint8_t),用来控制是否启用电源节省模式。
|
||||
* 当其值为1时,启用电源节省模式;当其值为0时,禁用电源节省模式。
|
||||
*/
|
||||
void OLED_SetPowerSave(uint8_t is_enable)
|
||||
{
|
||||
u8g2_SetPowerSave(&u8g2, is_enable); // 调用u8g2库的函数,设置OLED的电源节省模式状态
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取OLED缓冲区的 tile 高度。
|
||||
*
|
||||
* 该函数不接受参数。
|
||||
*
|
||||
* @return 返回OLED缓冲区的tile高度。返回值为uint8_t类型,即无符号8位整数。
|
||||
*/
|
||||
uint8_t OLED_GetBufferTileHeight(void)
|
||||
{
|
||||
return u8g2_GetBufferTileHeight(&u8g2); // 调用u8g2库函数,获取当前OLED缓冲区的tile高度
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取OLED缓冲区的单个瓦片宽度。
|
||||
*
|
||||
* 该函数查询U8G2图形库当前配置的OLED缓冲区的单个瓦片宽度。瓦片宽度是指OLED屏幕
|
||||
* 在显示更新时,一次可以处理的像素宽度。这个值通常取决于OLED屏幕的物理分辨率
|
||||
* 和U8G2库的内部处理方式。
|
||||
*
|
||||
* @return 返回OLED缓冲区单个瓦片的宽度,单位为字节。
|
||||
*/
|
||||
uint8_t OLED_GetBufferTileWidth(void)
|
||||
{
|
||||
return u8g2_GetBufferTileWidth(&u8g2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取OLED显示缓冲区的指针
|
||||
*
|
||||
* 该函数用于获取当前OLED显示设备的显示缓冲区的指针。该缓冲区是一个uint8_t类型的数组,
|
||||
* 用于存储即将显示在OLED屏幕上的图像数据。
|
||||
*
|
||||
* @return 返回类型为uint8_t*,指向OLED显示缓冲区的起始位置。
|
||||
*/
|
||||
uint8_t *OLED_GetBufferPtr(void)
|
||||
{
|
||||
// 调用u8g2库的函数获取显示缓冲区指针
|
||||
return u8g2_GetBufferPtr(&u8g2);
|
||||
}
|
||||
29
Middlewares/MultMenu/disp/dispDirver.h
Normal file
29
Middlewares/MultMenu/disp/dispDirver.h
Normal file
@ -0,0 +1,29 @@
|
||||
#ifndef _DISP_DRIVER_H_
|
||||
#define _DISP_DRIVER_H_
|
||||
|
||||
//#include "main.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void Disp_Init(void);
|
||||
void OLED_ClearBuffer(void);
|
||||
void OLED_SendBuffer(void);
|
||||
uint16_t OLED_GetStrWidth(const char *s);
|
||||
void OLED_SetMaxClipWindow(void);
|
||||
void OLED_SetFont(const uint8_t *font);
|
||||
void OLED_DrawPixel(uint16_t x, uint16_t y);
|
||||
void OLED_DrawLine(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
|
||||
uint16_t OLED_DrawStr(uint16_t x, uint16_t y, const char *str);
|
||||
void OLED_SetDrawColor(uint8_t color);
|
||||
void OLED_DrawFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void OLED_DrawRFrame(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r);
|
||||
void OLED_DrawBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
|
||||
void OLED_DrawRBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r);
|
||||
void OLED_DrawXBMP(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const uint8_t *bitmap);
|
||||
void OLED_SetContrast(uint8_t value);
|
||||
void OLED_SetPowerSave(uint8_t is_enable);
|
||||
uint8_t OLED_GetBufferTileHeight(void);
|
||||
uint8_t OLED_GetBufferTileWidth(void);
|
||||
uint8_t *OLED_GetBufferPtr(void);
|
||||
|
||||
#endif
|
||||
766
Middlewares/MultMenu/menu/menu.c
Normal file
766
Middlewares/MultMenu/menu/menu.c
Normal file
@ -0,0 +1,766 @@
|
||||
#include "menu.h"
|
||||
#include "dispDirver.h"
|
||||
#include "stdlib.h"
|
||||
#include "application.h"
|
||||
#include "DinoGame.h"
|
||||
#include "AirPlane.h"
|
||||
#include "usbd_cdc_if.h"
|
||||
#include "usart.h"
|
||||
#include "main.h"
|
||||
|
||||
|
||||
/* pid动画参数 */
|
||||
Pid_Error Cursor_Line = {600, 370, 30, 0, 0, 0}, Cursor_Wide = {250, 370, 30, 0, 0, 0};
|
||||
/* 线性动画参数 */
|
||||
Animation_Param AnimationParam = {10, 0, 0, 0, 0, 0, 0, 0, false};
|
||||
/* Page*/
|
||||
xPage Home_Page ;
|
||||
xPage setting_page;
|
||||
xPage tx_mode_page;
|
||||
xPage rx_mode_page;
|
||||
/* item */
|
||||
xItem HomeHead_Item ;
|
||||
xItem setting_item;
|
||||
xItem setting_exit_item;
|
||||
xItem work_mode_item;
|
||||
xItem rate_mode_item;
|
||||
xItem channel_item;
|
||||
xItem tx_power_item;
|
||||
xItem tx_count_item;
|
||||
xItem tx_mode_item;
|
||||
xItem rx_mode_item;
|
||||
xItem version_item;
|
||||
xItem reset_item;
|
||||
xItem bg_color_item;
|
||||
/* menu */
|
||||
xMenu Menu = {0, &HomeHead_Item, &HomeHead_Item, MENU_INIT, PAGE_STATIC, 0};
|
||||
|
||||
/**
|
||||
* 向指定页面添加一个项目。
|
||||
*
|
||||
* @param Name 项目名称。
|
||||
* @param Type 项目类型。
|
||||
* @param Data 项目关联的数据指针。
|
||||
* @param item 待添加的项目结构体。
|
||||
* @param LocalPage 项目所属的页面。
|
||||
* @param nextpage 项目跳转到的下一个页面。
|
||||
* @param function 项目关联的函数指针。
|
||||
*
|
||||
* 项目会被添加到指定页面的链表中,并且会更新页面的相关信息。
|
||||
*/
|
||||
static void AddItem(const char *Name, Item_Type Type, void *Data, xpItem item, xpPage LocalPage, xpPage nextpage, ItemFunction function)
|
||||
{
|
||||
// 参数检验
|
||||
if (!Name || !item || !LocalPage || (Type == DATA && !Data)) {
|
||||
printf("Invalid parameter(s)\n");
|
||||
return; // 早期返回以避免进一步错误
|
||||
}
|
||||
|
||||
item->itemName = Name; // 设置项目名称
|
||||
item->itemType = Type; // 设置项目类型
|
||||
// 如果项目类型为DATA,则设置数据指针
|
||||
if(Type == DATA)item->data.ptr = (int *)Data;
|
||||
|
||||
item->page.location = LocalPage; // 设置项目所在页面
|
||||
item->itemFunction= function; // 设置项目关联的函数
|
||||
|
||||
/* 初始化项目下一个项为NULL */
|
||||
item->nextItem = NULL;
|
||||
|
||||
/* 设置跳转页面的父级项目 */
|
||||
if (nextpage != NULL)
|
||||
nextpage->item.parent = item;
|
||||
else // 如果没有下一个页面,则设置为当前页面
|
||||
nextpage = LocalPage;
|
||||
item->page.jumpPage = nextpage; // 设置项目跳转页面
|
||||
|
||||
/* 链式结构创建项目 */
|
||||
if (LocalPage->item.head == NULL) // 如果是首个项目
|
||||
{
|
||||
// 初始化项目链表头部和尾部
|
||||
item->lastItem = item;
|
||||
LocalPage->item.head = item;
|
||||
LocalPage->item.tail = item;
|
||||
LocalPage->length = 0; // 初始化项目计数
|
||||
}
|
||||
else // 如果不是首个项目
|
||||
{
|
||||
// 连接新项目到链表尾部
|
||||
item->lastItem = LocalPage->item.tail; // 新项目上一个项指向当前尾项目
|
||||
LocalPage->item.tail->nextItem = item; // 尾项目下一个项指向新项目
|
||||
LocalPage->item.tail = LocalPage->item.tail->nextItem; // 更新尾项目为新项目
|
||||
LocalPage->length++; // 项目计数加一
|
||||
}
|
||||
item->id = LocalPage->length; // 设置项目ID为当前页面项目计数
|
||||
// 关联页面的头尾项目互相指向,用于快速遍历
|
||||
LocalPage->item.tail->nextItem = LocalPage->item.head;
|
||||
LocalPage->item.head->lastItem = LocalPage->item.tail;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 向页面中添加一个新页面。
|
||||
*
|
||||
* @param name 新页面的名称。
|
||||
* @param Menu 新页面所在菜单。
|
||||
* @param page 指向新页面结构体的指针。
|
||||
* @param item 新页面对应的项。
|
||||
* @param LocalPage 当前局部页面的指针。
|
||||
* @param nextpage 下一个页面的指针。
|
||||
* @param function 项的功能函数指针。
|
||||
*/
|
||||
static void AddPage(const char *name, xpMenu Menu, xpPage page, xpItem item, xpPage LocalPage, xpPage nextpage, ItemFunction function)
|
||||
{
|
||||
// 初始化新页面的基本信息
|
||||
page->pageName = name;
|
||||
page->item.head = NULL;
|
||||
page->item.tail = NULL;
|
||||
page->menu = Menu;
|
||||
Menu->page_length++;
|
||||
page->id = Menu->page_length; // 分配ID,并递增ID值
|
||||
// 如果是第一个页面,将其头跳转至首页;否则,将其父项设置为上一页
|
||||
if (page->id == 1)AddItem(name, LOOP_FUNCTION, NULL, item, LocalPage, nextpage, function);
|
||||
else AddItem(name, PARENTS, NULL, item, LocalPage, nextpage, function);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用线性插值公式计算当前时间点对应的插值结果。
|
||||
*
|
||||
* @param AllTime 总时间长度,单位为秒。表示从开始到结束的总时间长度。
|
||||
* @param Time_Now 当前时间点,单位为秒。表示在总时间长度中的当前位置。
|
||||
* @param Targrt 目标值。在给定总时间长度和当前时间点的情况下,此函数将计算出达到此目标值的插值。
|
||||
* @param Now 当前值。表示在当前时间点的值。
|
||||
* @return 返回计算出的插值结果。此结果是根据线性插值公式,将目标值和当前值结合当前时间点与总时间长度计算得出的。
|
||||
*/
|
||||
static int8_t Linear(uint8_t AllTime, uint8_t Time_Now, int8_t Targrt, int8_t Now)
|
||||
{
|
||||
// 根据线性插值公式,计算并返回当前时间点对应的插值结果
|
||||
return (Targrt - Now)*Time_Now/AllTime + Now;
|
||||
}
|
||||
|
||||
/**
|
||||
* PID 插值控制器计算函数
|
||||
*
|
||||
* 本函数用于根据目标值、当前值及已设定的PID参数,计算出下一时刻的控制量。
|
||||
*
|
||||
* @param Targrt 目标值,即期望的控制结果。
|
||||
* @param Now 当前值,即当前的控制结果。
|
||||
* @param Obj PID控制器的结构体对象,包含比例、积分、微分系数及误差相关信息。
|
||||
* @return 计算后得到的控制量,用于调整系统状态。
|
||||
*/
|
||||
static int PID(int Targrt, int Now, Pid_Error *Obj)
|
||||
{
|
||||
int x = Now;
|
||||
// 将PID系数从毫单位转换为浮点数
|
||||
float Kp = (float)(Obj->kp)/1000.00, Ki = (float)(Obj->ki)/1000.00, Kd = (float)(Obj->kd)/1000.00;
|
||||
|
||||
// 计算误差
|
||||
Obj->error = Targrt - x;
|
||||
// 积分环节,累加误差
|
||||
Obj->sum_srror += Obj->error;
|
||||
// 微分环节,计算误差变化率
|
||||
float delta_error = Obj->error - Obj->last_error;
|
||||
|
||||
// 计算控制量
|
||||
float velocity = Kp * Obj->error + Ki * Obj->sum_srror + Kd * delta_error;
|
||||
|
||||
// 更新状态
|
||||
x += velocity;
|
||||
Obj->last_error = Obj->error;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
static void Change_MenuState(Menu_State state)
|
||||
{
|
||||
Menu.menu_state = state;
|
||||
}
|
||||
|
||||
static void Item_AnimationParam_Init(void)
|
||||
{
|
||||
AnimationParam.Item_NowLine = 0;
|
||||
AnimationParam.Item_NowWide = 0;
|
||||
AnimationParam.Item_TargrtLine = 0;
|
||||
AnimationParam.Item_TargrtWide = 0;
|
||||
AnimationParam.OptionState = false;
|
||||
}
|
||||
|
||||
static void DialogScale_AnimationParam_Init(void)
|
||||
{
|
||||
AnimationParam.DialogScale_InitHigh = 0;
|
||||
AnimationParam.DialogScale_InitWide = 0;
|
||||
AnimationParam.DialogScale_time = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制对话框
|
||||
* @param x 对话框左上角x坐标
|
||||
* @param y 对话框左上角y坐标
|
||||
* @param w 对话框宽度
|
||||
* @param h 对话框高度
|
||||
* 该函数首先绘制对话框的边框,然后绘制对话框的背景盒。
|
||||
* 使用了OLED显示设备的相关函数来完成绘制操作。
|
||||
*/
|
||||
void Draw_DialogBox(uint16_t x,uint16_t y,uint16_t w,uint16_t h)
|
||||
{
|
||||
// 设置绘制边框的颜色,并绘制边框
|
||||
OLED_SetDrawColor(Menu.BgColor^0x01);
|
||||
OLED_DrawFrame(x, y, w, h);
|
||||
|
||||
// 设置绘制背景的颜色,并绘制背景盒
|
||||
OLED_SetDrawColor(Menu.BgColor);
|
||||
OLED_DrawBox(x+1, y+1, w-2, h-2);
|
||||
|
||||
// 设置边框高亮颜色(通常与背景色异或得到),用于强调边框
|
||||
OLED_SetDrawColor(Menu.BgColor^0x01);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 显示一个按指定尺寸缩放的对话框。
|
||||
*
|
||||
* 此函数用于在应用绘制状态时,通过线性动画效果展示一个对话框的缩放过程。函数首先检查当前是否处于应用绘制状态,
|
||||
* 如果是,则根据设定的时间和目标尺寸计算当前对话框的宽度和高度,并进行绘制。当动画时间达到预设的对话框显示时间
|
||||
* 后,将状态切换到应用运行状态,并返回true。整个过程通过OLED发送缓冲区来更新显示。
|
||||
*
|
||||
* @param x 对话框的x坐标。
|
||||
* @param y 对话框的y坐标。
|
||||
* @param Targrt_w 目标对话框的宽度。
|
||||
* @param Targrt_h 目标对话框的高度。
|
||||
* @return bool 如果动画时间达到预设的对话框显示时间,则返回true;否则返回false。
|
||||
*/
|
||||
bool DialogScale_Show(uint8_t x,uint8_t y,uint8_t Targrt_w,uint8_t Targrt_h)
|
||||
{
|
||||
// 当前处于应用绘制状态时,处理对话框的缩放动画
|
||||
if (Menu.menu_state == APP_DRAWING)
|
||||
{
|
||||
AnimationParam.DialogScale_time++; // 动画时间递增
|
||||
// 根据当前时间和目标尺寸计算对话框的当前宽度
|
||||
AnimationParam.DialogScale_InitWide = Linear(AnimationParam.Dialog_AllTime, AnimationParam.DialogScale_time, Targrt_w, AnimationParam.DialogScale_InitWide);
|
||||
// 根据当前时间和目标尺寸计算对话框的当前高度
|
||||
AnimationParam.DialogScale_InitHigh = Linear(AnimationParam.Dialog_AllTime, AnimationParam.DialogScale_time, Targrt_h, AnimationParam.DialogScale_InitHigh);
|
||||
// 绘制当前尺寸的对话框
|
||||
Draw_DialogBox(x, y, AnimationParam.DialogScale_InitWide, AnimationParam.DialogScale_InitHigh);
|
||||
}
|
||||
// 当动画时间达到预设的对话框显示时间时,切换到应用运行状态
|
||||
if (AnimationParam.DialogScale_time == AnimationParam.Dialog_AllTime)
|
||||
{
|
||||
Change_MenuState(APP_RUN);
|
||||
return true;
|
||||
}
|
||||
// 更新OLED显示缓冲区
|
||||
OLED_SendBuffer();
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制一个带有圆角的对话框背景框
|
||||
* @param x 对话框左上角x坐标
|
||||
* @param y 对话框左上角y坐标
|
||||
* @param w 对话框宽度
|
||||
* @param h 对话框高度
|
||||
* @param r 对话框圆角半径
|
||||
*/
|
||||
void Draw_DialogRBox(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r)
|
||||
{
|
||||
// 设置绘制边框的颜色,先绘制外边框
|
||||
OLED_SetDrawColor(Menu.BgColor^0x01);
|
||||
OLED_DrawRFrame(x, y, w, h, r);
|
||||
|
||||
// 设置绘制填充颜色,绘制内框,即填充部分
|
||||
OLED_SetDrawColor(Menu.BgColor);
|
||||
OLED_DrawRBox(x + 1, y + 1, w - 2, h - 2, r);
|
||||
|
||||
// 设置边框颜色,用于强调边框,这里使用与背景色异或的方式
|
||||
OLED_SetDrawColor(Menu.BgColor^0x01);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景颜色
|
||||
* @param color 要设置的颜色值,类型为uint8_t
|
||||
* 该函数用于将全局背景颜色设置为指定的颜色值。
|
||||
*/
|
||||
void Set_BgColor(uint8_t color)
|
||||
{
|
||||
Menu.BgColor = color; // 设置背景颜色
|
||||
}
|
||||
|
||||
uint8_t Get_BgColor(void)
|
||||
{
|
||||
return Menu.BgColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制一个滚动条
|
||||
* 该函数根据给定的参数,在OLED屏幕上绘制一个滚动条。滚动条的可见部分的长度
|
||||
* 会根据当前值在最小值和最大值之间动态调整。
|
||||
* @param x 滚动条左上角的x坐标
|
||||
* @param y 滚动条左上角的y坐标
|
||||
* @param w 滚动条的宽度
|
||||
* @param h 滚动条的高度
|
||||
* @param r 滚动条圆角的半径
|
||||
* @param min 滚动条代表的最小值
|
||||
* @param max 滚动条代表的最大值
|
||||
* @param step 滚动条的步进值
|
||||
* @param NowValue 滚动条当前的值
|
||||
*/
|
||||
int Draw_Scrollbar(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, double min, double max, int step, int NowValue)
|
||||
{
|
||||
int value = NowValue;
|
||||
|
||||
// 根据当前值计算滚动条可见部分的长度
|
||||
if ((value <= max) && (value >= min))
|
||||
{
|
||||
value += step;
|
||||
if (value > max)
|
||||
{
|
||||
value = max;
|
||||
}
|
||||
if (value < min)
|
||||
{
|
||||
value = min;
|
||||
}
|
||||
|
||||
double value = (double)(abs(value - min) * ((w - 6)) / (double)((max - min)) + 6);
|
||||
// 绘制滚动条的填充部分
|
||||
OLED_SetDrawColor(Menu.BgColor);
|
||||
OLED_DrawRBox(x + (uint16_t)value, y, w-(uint16_t)value, h, r);
|
||||
OLED_SetDrawColor(Menu.BgColor^0x01);
|
||||
OLED_DrawRBox(x, y, (uint16_t)value, h, r);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 使屏幕上的内容逐渐消失的函数
|
||||
*
|
||||
* @param disapper 一个用于控制消失程度的参数,初始值建议为0,每次调用本函数会自动增加
|
||||
* @return uint8_t 返回调整后的disapper值,用于下次调用时继续消失过程
|
||||
*/
|
||||
static uint8_t ui_disapper(uint8_t disapper)
|
||||
{
|
||||
short disapper_temp = 0;
|
||||
// 计算屏幕缓冲区的总长度
|
||||
int length = 8 * OLED_GetBufferTileHeight() * OLED_GetBufferTileWidth();
|
||||
uint8_t *p = OLED_GetBufferPtr(); // 获取屏幕缓冲区的指针
|
||||
|
||||
// 如果背景色为黑色,那么执行与操作,让像素点逐渐变暗从而消失
|
||||
if(Menu.BgColor==0)
|
||||
{
|
||||
for( int i = 0; i < length; i++)
|
||||
{
|
||||
p[i] = p[i] & (rand()%0xff) >> disapper; // 通过与操作使像素点变暗
|
||||
}
|
||||
}
|
||||
else // 如果背景色不是黑色,执行或操作,让像素点逐渐变亮从而消失
|
||||
{
|
||||
for( int i = 0; i < length; i++)
|
||||
{
|
||||
p[i] = p[i] | (rand()%0xff) >> disapper; // 通过或操作使像素点变亮
|
||||
}
|
||||
}
|
||||
|
||||
disapper += 2; // 每次调用使消失程度增加,以便逐渐完成消失过程
|
||||
if(disapper >= 8) // 当消失程度达到最大值时重置为0,准备下一次调用
|
||||
{
|
||||
disapper = 0;
|
||||
}
|
||||
|
||||
OLED_SendBuffer(); // 将更新后的缓冲区内容发送到OLED显示设备
|
||||
disapper_temp = disapper;
|
||||
return disapper_temp; // 返回调整后的disapper值,供外部调用者使用
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 绘制选项位置
|
||||
*
|
||||
* 该函数用于在OLED屏幕上动态绘制选项的位置,实现类似选项滑动选择的效果。
|
||||
* 根据当前项和下一个项的信息,计算并绘制出选项的滑动过程。
|
||||
*
|
||||
* @param now_item 当前选项项的指针
|
||||
* @param next_item 下一个选项项的指针
|
||||
* @return bool 如果绘制过程完成(达到设定的时间),返回true;否则返回false。
|
||||
*/
|
||||
static bool Draw_OptionPlace(xpItem now_item, xpItem next_item)
|
||||
{
|
||||
static uint8_t t; // 控制绘制过程的时间变量
|
||||
static uint8_t Now_Lenght; // 当前绘制长度
|
||||
static uint8_t Next_Lenght; // 下一个选项的理论绘制长度
|
||||
// 根据下一个项的id和位置长度,计算其理论绘制长度
|
||||
Next_Lenght = (VER_RES / (float)(next_item->page.location->length)) * next_item->id;
|
||||
t++; // 时间变量递增
|
||||
// 使用线性插值计算当前的绘制长度
|
||||
Now_Lenght = Linear(AnimationParam.Dialog_AllTime, t, Next_Lenght, Now_Lenght);
|
||||
// 绘制选项移动的指示线
|
||||
OLED_DrawLine(HOR_RES - 7, 0, HOR_RES - 7, VER_RES);
|
||||
// 根据计算出的长度,绘制当前选项的高亮框
|
||||
OLED_DrawBox(HOR_RES - 10, 0, 6, Now_Lenght);
|
||||
// 如果绘制时间达到预设的Dialog_Time,重置时间变量并返回true
|
||||
if(t == AnimationParam.Dialog_AllTime)
|
||||
{
|
||||
t = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 绘制指定位置的页面
|
||||
*
|
||||
* @param pos 页面绘制的起始位置
|
||||
* @param Page 指向当前页面结构体的指针
|
||||
* @param LineSpacing 行间距
|
||||
* @param now_item 当前选中的项目
|
||||
* @param next_item 下一个将要选中的项目
|
||||
*/
|
||||
static void Draw_Page(uint8_t pos, xpPage Page, xpItem now_item, xpItem next_item)
|
||||
{
|
||||
char Data[10] = {0}; // 用于临时存储数据字符串
|
||||
static int16_t first_line = FirstLine; // 页面中第一行的起始位置
|
||||
|
||||
xpItem temp = Page->item.head; // 从页面的头部开始遍历
|
||||
|
||||
// 初始化或计算页面滚动时的起始绘制位置
|
||||
if(Menu.menu_state == MENU_RUN)
|
||||
{
|
||||
// 页面切换时重置第一行位置
|
||||
if(next_item->page.location != now_item->page.location)first_line = FirstLine;
|
||||
|
||||
// 计算页面滚动的距离
|
||||
if (Menu.page_state == PAGE_MOVING)
|
||||
{
|
||||
if ((next_item->id - now_item->id) > 0)first_line -= ((next_item->id - now_item->id) > (Page->length - MaxVisible_Number)) ? ((Page->length - MaxVisible_Number) * Font_Size) : Font_Size;
|
||||
else first_line += ((now_item->id - next_item->id) > (Page->length - MaxVisible_Number)) ? ((Page->length - MaxVisible_Number) * Font_Size) : Font_Size;
|
||||
Menu.page_state = PAGE_STATIC; // 更新页面状态为静态显示
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历页面中的所有项目并绘制
|
||||
for (uint16_t i = 0; i <= Page->length; i++)
|
||||
{
|
||||
OLED_DrawStr(pos, first_line + i * Font_Size, temp->itemName); // 绘制项目名称
|
||||
|
||||
// 根据项目类型进行特殊绘制处理
|
||||
if(temp->itemType == SWITCH)
|
||||
{
|
||||
// 绘制开关状态
|
||||
if(temp->switchState == false)OLED_DrawFrame(pos + 95, first_line + i * Font_Size - Font_Size + 3, 10, 10);
|
||||
else OLED_DrawBox(pos + 95, first_line + i * Font_Size - Font_Size + 3, 10, 10);
|
||||
}
|
||||
if(temp->itemType == DATA)
|
||||
{
|
||||
// 格式化并绘制数据
|
||||
sprintf(Data, "%d", *temp->data.ptr);
|
||||
OLED_DrawStr(pos + 95, first_line + i * Font_Size, Data);
|
||||
}
|
||||
|
||||
temp = temp->nextItem; // 移动到下一个项目
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制菜单界面
|
||||
* 该函数负责在 OLED 屏幕上绘制菜单界面,包括计算各项的位置、绘制背景、选项及其高亮显示。
|
||||
* 根据不同的菜单状态(如页面移动、选项切换),动态调整选项的显示位置,实现平滑的动画效果。
|
||||
* @param pos 当前页面位置
|
||||
* @param Page 当前页面结构体
|
||||
* @param LineSpacing 行间距
|
||||
* @param now_item 当前选中项
|
||||
* @param next_item 下一个将要选中的项
|
||||
*/
|
||||
static void Draw_Menu(uint8_t pos, xpPage Page, xpItem now_item,xpItem next_item)
|
||||
{
|
||||
// 初始化或更新动画参数及页面状态
|
||||
if(Menu.menu_state == MENU_RUN)
|
||||
{
|
||||
// 计算当前项名称的宽度
|
||||
AnimationParam.Item_NowWide = strlen(now_item->itemName)*6 + 4;
|
||||
|
||||
// 切换页面时进行初始化并设置页面状态为静态
|
||||
if(next_item->page.location != now_item->page.location)
|
||||
{
|
||||
Item_AnimationParam_Init();
|
||||
Menu.page_state = PAGE_STATIC;
|
||||
}
|
||||
else // 在同一页面内切换选项时的处理
|
||||
{
|
||||
// 根据选项的id差值计算目标行位置,并限制在可视范围内
|
||||
if (next_item->id > now_item->id)
|
||||
{
|
||||
AnimationParam.Item_TargrtLine += ((next_item->id - now_item->id)*Font_Size);
|
||||
if (AnimationParam.Item_TargrtLine > LINE_MAX) // 防止光标溢出可视范围
|
||||
{
|
||||
Menu.page_state = PAGE_MOVING;
|
||||
AnimationParam.Item_TargrtLine = LINE_MAX;
|
||||
}
|
||||
}
|
||||
else if(next_item->id < now_item->id)
|
||||
{
|
||||
AnimationParam.Item_TargrtLine -= ((now_item->id - next_item->id)*Font_Size);
|
||||
if (AnimationParam.Item_TargrtLine < 0) // 防止光标溢出可视范围
|
||||
{
|
||||
Menu.page_state = PAGE_MOVING;
|
||||
AnimationParam.Item_TargrtLine = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 计算下一个将要选中项的名称宽度
|
||||
AnimationParam.Item_TargrtWide = OLED_GetStrWidth(next_item->itemName) + 3;
|
||||
|
||||
// 开始绘制菜单界面
|
||||
OLED_ClearBuffer(); // 清除屏幕缓冲区
|
||||
OLED_SetDrawColor(Menu.BgColor); // 设置背景颜色
|
||||
OLED_DrawBox(0, 0, 128, 64); // 绘制屏幕背景框
|
||||
OLED_SetDrawColor(Menu.BgColor^0x01); // 设置绘制颜色为高亮或低亮
|
||||
AnimationParam.OptionState = Draw_OptionPlace(now_item, next_item); // 绘制选项及其位置
|
||||
Draw_Page(pos, Page, now_item, next_item); // 绘制页面内容
|
||||
OLED_SetDrawColor(2); // 设置特定的颜色,通常用于高亮显示
|
||||
// 根据目标位置和当前位置,以及PID算法计算并更新当前选项的位置和宽度
|
||||
AnimationParam.Item_NowLine = PID(AnimationParam.Item_TargrtLine, AnimationParam.Item_NowLine, &Cursor_Line);
|
||||
AnimationParam.Item_NowWide = PID(AnimationParam.Item_TargrtWide, AnimationParam.Item_NowWide, &Cursor_Wide);
|
||||
// 绘制选中项的高亮边框
|
||||
OLED_DrawBox(pos+1, AnimationParam.Item_NowLine+2, AnimationParam.Item_NowWide, Font_Size);
|
||||
OLED_SendBuffer(); // 将缓冲区的内容发送到OLED屏幕显示
|
||||
|
||||
// 更新菜单状态为绘制中
|
||||
Change_MenuState(MENU_DRAWING);
|
||||
// 如果动画参数达到目标值且选项绘制完成,则更新菜单状态为运行中
|
||||
if ((AnimationParam.Item_NowLine == AnimationParam.Item_TargrtLine) && (AnimationParam.Item_NowWide == AnimationParam.Item_TargrtWide) && (AnimationParam.OptionState == true))
|
||||
{
|
||||
Change_MenuState(MENU_RUN);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 菜单构建函数
|
||||
* 该函数不接受参数,也不返回任何值。
|
||||
* 功能:静态地构建一个菜单系统。
|
||||
*/
|
||||
static void Menu_Team(void)
|
||||
{
|
||||
AddPage("[Home]", &Menu, &Home_Page, &HomeHead_Item, &Home_Page, NULL, logo_callback );
|
||||
AddItem(" +Setting", PARENTS, NULL, &setting_item, &Home_Page, &setting_page, NULL);
|
||||
AddPage("[Exit]", &Menu, &setting_page, &setting_exit_item, &setting_page, &Home_Page, NULL);
|
||||
AddItem(" -Work Mode", DATA, &user_config.work_mode, &work_mode_item, &setting_page, NULL, work_mode_callback );
|
||||
AddItem(" -Rate Mode", DATA, &user_config.rate_mode, &rate_mode_item, &setting_page, NULL, rate_mode_callback );
|
||||
AddItem(" -Channel", DATA, &user_config.channel, &channel_item, &setting_page, NULL, channel_callback );
|
||||
AddItem(" -TX Power", DATA, &user_config.tx_power, &tx_power_item, &setting_page, NULL, tx_power_callback);
|
||||
AddItem(" -TX Count", DATA, &user_config.tx_count, &tx_count_item, &setting_page, NULL, tx_count_callback);
|
||||
AddItem(" -Back Color", SWITCH, NULL, &bg_color_item, &setting_page, NULL, background_color_callback );
|
||||
AddItem(" -Tx XTELL", LOOP_FUNCTION, NULL, &tx_mode_item, &Home_Page, NULL, tx_mode_callback);
|
||||
AddItem(" -Rx XTELL", LOOP_FUNCTION, NULL, &rx_mode_item, &Home_Page, NULL, rx_mode_callback);
|
||||
AddItem(" -Version", LOOP_FUNCTION, NULL, &version_item, &Home_Page, NULL, version_callback);
|
||||
AddItem(" -Reset", LOOP_FUNCTION, NULL, &reset_item, &Home_Page, NULL, reset_callback);
|
||||
}
|
||||
|
||||
/* 在此填入按键扫描程序
|
||||
* 功能:执行按键扫描,根据接收到的数据确定按键方向
|
||||
* 参数:无
|
||||
* 返回值:Menu_Direction 枚举类型,表示按键的方向,没有按键按下时返回MENU_NONE
|
||||
*/
|
||||
static Menu_Direction BtnScan(void)
|
||||
{
|
||||
if( key_check_press( KEY_NAME_UP ) == true )
|
||||
{
|
||||
buzzer_button_press();
|
||||
return MENU_UP;
|
||||
}
|
||||
|
||||
if( key_check_press( KEY_NAME_DOWN ) == true )
|
||||
{
|
||||
buzzer_button_press();
|
||||
return MENU_DOWN;
|
||||
}
|
||||
|
||||
if( key_check_press( KEY_NAME_ENTER ) == true )
|
||||
{
|
||||
buzzer_button_press();
|
||||
return MENU_ENTER;
|
||||
}
|
||||
|
||||
return MENU_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 根据菜单方向运行处理菜单逻辑
|
||||
*
|
||||
* @param Dir 菜单操作方向,包括上、下、进入等操作
|
||||
*/
|
||||
void Process_Menu_Run(Menu_Direction Dir)
|
||||
{
|
||||
uint8_t disapper = 0;
|
||||
switch (Menu.menu_state) // 根据当前菜单状态进行不同的操作
|
||||
{
|
||||
case MENU_RUN:
|
||||
switch (Dir) // 根据操作方向更新菜单项
|
||||
{
|
||||
case MENU_UP:
|
||||
// 向上移动菜单项,确保当前项和上一项非空
|
||||
if (Menu.now_item != NULL && Menu.now_item->lastItem != NULL)
|
||||
{
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.location, Menu.now_item, Menu.now_item->lastItem);
|
||||
Menu.old_item = Menu.now_item;
|
||||
Menu.now_item = Menu.now_item->lastItem;
|
||||
}
|
||||
break;
|
||||
case MENU_DOWN:
|
||||
// 向下移动菜单项,确保当前项和下一项非空
|
||||
if (Menu.now_item != NULL && Menu.now_item->nextItem != NULL)
|
||||
{
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.location, Menu.now_item, Menu.now_item->nextItem);
|
||||
Menu.old_item = Menu.now_item;
|
||||
Menu.now_item = Menu.now_item->nextItem;
|
||||
}
|
||||
break;
|
||||
case MENU_ENTER:
|
||||
// 当前项非空且为父项时,进入下一级菜单
|
||||
if(Menu.now_item != NULL && Menu.now_item->itemType == PARENTS)
|
||||
{
|
||||
// 避免重复状态改变
|
||||
if(Menu.menu_state != MENU_ENTER) Change_MenuState(MENU_RUN);
|
||||
|
||||
for (size_t i = 0; i < 8; i++) // 执行UI淡出操作
|
||||
{
|
||||
disapper = ui_disapper(disapper);
|
||||
}
|
||||
|
||||
// 如果存在跳转页面且不为空,则绘制跳转页面并更新当前项
|
||||
if(Menu.now_item->page.jumpPage != NULL && Menu.now_item->page.jumpPage->item.head != NULL)
|
||||
{
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.jumpPage, Menu.now_item, Menu.now_item->page.jumpPage->item.head);
|
||||
Menu.old_item = Menu.now_item;
|
||||
Menu.now_item = Menu.now_item->page.jumpPage->item.head;
|
||||
}
|
||||
}
|
||||
else // 如果当前项为空或非父项,则进入应用绘制状态
|
||||
{
|
||||
ui_disapper(1);
|
||||
Change_MenuState(APP_DRAWING);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.location, Menu.now_item, Menu.now_item);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case APP_QUIT:
|
||||
// 退出应用时的初始化操作,并返回菜单运行状态
|
||||
DialogScale_AnimationParam_Init();
|
||||
Change_MenuState(MENU_RUN);
|
||||
for (size_t i = 0; i < 8; i++)
|
||||
{
|
||||
disapper = ui_disapper(disapper); // 执行UI淡出操作
|
||||
}
|
||||
if(Menu.now_item != NULL) // 确保now_item非空
|
||||
{
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.location, Menu.now_item, Menu.now_item);
|
||||
}
|
||||
break;
|
||||
case MENU_DRAWING:
|
||||
// 如果当前正在绘制菜单,则根据方向进行状态更新和菜单重绘
|
||||
if(Menu.now_item != NULL && Menu.old_item != NULL)
|
||||
{
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.location, Menu.old_item, Menu.now_item);
|
||||
if (Dir != MENU_NONE)
|
||||
{
|
||||
Change_MenuState(MENU_RUN);
|
||||
Process_Menu_Run(Dir);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 处理应用程序的运行状态。
|
||||
* 对给定的项目(item)根据其类型(ItemType)和当前的菜单状态(State)执行相应的操作。
|
||||
* @param item 指向要处理的项目的指针。
|
||||
* @param State 当前菜单的方向或状态。
|
||||
*/
|
||||
void Process_App_Run(xpItem item, Menu_Direction State)
|
||||
{
|
||||
if (item == NULL) return; // 检查空指针,避免未定义行为
|
||||
|
||||
item->state = State; // 设置项目的状态为当前菜单状态
|
||||
|
||||
switch (item->itemType) // 根据项目类型执行不同的操作
|
||||
{
|
||||
case DATA:
|
||||
case LOOP_FUNCTION:
|
||||
if (item->itemFunction != NULL)(item->itemFunction)(item); // 执行项目的函数
|
||||
if(item->state == MENU_ENTER)Change_MenuState(APP_QUIT); // 如果项目状态为进入菜单,则改变菜单状态为函数退出
|
||||
break;
|
||||
case SWITCH:
|
||||
item->switchState = ! item->switchState; // 切换开关状态
|
||||
case ONCE_FUNCTION:
|
||||
if (item->itemFunction != NULL)(item->itemFunction)(item); // 如果项目有函数,则执行该函数
|
||||
Change_MenuState(APP_QUIT); // 改变菜单状态为函数退出
|
||||
break;
|
||||
default:
|
||||
break; // 对未知类型不执行任何操作
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜单任务处理函数
|
||||
* 该函数负责根据当前按钮扫描结果更新菜单状态,并进行相应的绘制或处理操作。
|
||||
* 无参数
|
||||
* 无返回值
|
||||
*/
|
||||
void Menu_Task(void)
|
||||
{
|
||||
Menu_Direction Dir = BtnScan(); // 扫描按钮方向,确定菜单操作方向
|
||||
if (Menu.menu_state == MENU_INIT && Dir != MENU_NONE)
|
||||
{
|
||||
// 初始化状态下,非空检查now_item并绘制当前菜单项
|
||||
if (Menu.now_item != NULL)
|
||||
{
|
||||
Draw_Menu(FirstPos, Menu.now_item->page.location, Menu.now_item, Menu.now_item);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Menu.now_item is NULL\n"); // 打印错误信息,now_item为空
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (Menu.menu_state)
|
||||
{
|
||||
case MENU_INIT:break;
|
||||
case APP_RUN:
|
||||
case APP_DRAWING:
|
||||
// 在这两个状态下,处理应用程序运行逻辑
|
||||
Process_App_Run(Menu.now_item, Dir);
|
||||
if (Menu.menu_state == APP_DRAWING)
|
||||
{
|
||||
break; // 在绘制状态下,终止进一步流程执行
|
||||
}
|
||||
// 故意不写 break,以允许流程进入下方的共同逻辑处理(如果存在)
|
||||
|
||||
case MENU_RUN:
|
||||
case APP_QUIT:
|
||||
case MENU_DRAWING:
|
||||
// 处理菜单运行、应用退出和菜单绘制状态
|
||||
Process_Menu_Run(Dir);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Menu_Init(void)
|
||||
{
|
||||
Disp_Init();
|
||||
|
||||
Menu_Team();
|
||||
|
||||
logo_callback( NULL );
|
||||
}
|
||||
16
Middlewares/MultMenu/menu/menu.h
Normal file
16
Middlewares/MultMenu/menu/menu.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef __MENU_H__
|
||||
#define __MENU_H__
|
||||
|
||||
#include "stdbool.h"
|
||||
#include "menuConfig.h"
|
||||
|
||||
void Draw_DialogBox(uint16_t x,uint16_t y,uint16_t w,uint16_t h);
|
||||
void Draw_DialogRBox(uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint16_t r);
|
||||
bool DialogScale_Show(uint8_t x,uint8_t y,uint8_t Targrt_w,uint8_t Targrt_h);
|
||||
void Set_BgColor(uint8_t color);
|
||||
uint8_t Get_BgColor(void);
|
||||
int Draw_Scrollbar(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t r, double min, double max, int step, int NowValue);
|
||||
void Menu_Task(void);
|
||||
void Menu_Init(void);
|
||||
|
||||
#endif
|
||||
178
Middlewares/MultMenu/menu/menuConfig.h
Normal file
178
Middlewares/MultMenu/menu/menuConfig.h
Normal file
@ -0,0 +1,178 @@
|
||||
#ifndef _MENUCONFIG_H_
|
||||
#define _MENUCONFIG_H_
|
||||
|
||||
#include "u8g2.h"
|
||||
#include "stdbool.h"
|
||||
|
||||
// 屏幕分辨率定义
|
||||
#define HOR_RES 128 // 水平分辨率
|
||||
#define VER_RES 64 // 垂直分辨率
|
||||
|
||||
// 菜单字体定义
|
||||
#define MENU_FONT u8g2_font_profont12_mf
|
||||
|
||||
// 字体尺寸定义
|
||||
#define Font_Size 12 // 字体高度
|
||||
|
||||
// 起始Y坐标,基于字体大小设定的第一行位置
|
||||
#define FirstLine Font_Size
|
||||
|
||||
// 起始X坐标
|
||||
#define FirstPos 0
|
||||
|
||||
// 最大可见项目数,除去标题栏
|
||||
#define MaxVisible_Number 4 // 可见菜单项数量
|
||||
|
||||
// 最大Y坐标,根据字体大小和最大可见项目数计算得出
|
||||
#define LINE_MAX Font_Size*MaxVisible_Number
|
||||
|
||||
// 最小Y坐标,即第一行的位置
|
||||
#define LINE_MIN Font_Size
|
||||
|
||||
/**
|
||||
* Pid_Error 结构体定义
|
||||
* 用于存储PID控制器的误差及调整参数
|
||||
*/
|
||||
typedef struct PidError
|
||||
{
|
||||
int kp; // 比例增益
|
||||
int ki; // 积分增益
|
||||
int kd; // 微分增益
|
||||
float error; // 当前误差
|
||||
float sum_srror; // 积累的误差
|
||||
float last_error; // 上一次的误差
|
||||
}Pid_Error;
|
||||
|
||||
// 菜单状态枚举: 定义了菜单及应用程序的不同运行状态
|
||||
typedef enum MenuState
|
||||
{
|
||||
MENU_INIT, // 菜单初始化状态
|
||||
MENU_DRAWING, // 菜单绘制状态
|
||||
MENU_RUN, // 菜单运行状态
|
||||
APP_RUN, // 应用程序运行状态
|
||||
APP_DRAWING, // 应用程序绘制状态
|
||||
APP_QUIT // 应用程序退出状态
|
||||
} Menu_State;
|
||||
|
||||
// 页面状态枚举
|
||||
// 用于表示页面的两种状态:移动和静止
|
||||
typedef enum PageState
|
||||
{
|
||||
PAGE_MOVING, // 页面正在移动
|
||||
PAGE_STATIC // 页面处于静止状态
|
||||
}Page_State;
|
||||
|
||||
// 菜单运动方向枚举
|
||||
// 这个枚举定义了菜单系统中可能的方向和操作,包括向上、向下、进入和退出等操作。
|
||||
typedef enum MenuDirection
|
||||
{
|
||||
MENU_NONE, // 无操作
|
||||
MENU_UP, // 向上
|
||||
MENU_DOWN, // 向下
|
||||
MENU_ENTER // 进入或选择
|
||||
} Menu_Direction;
|
||||
|
||||
// 菜单项目类型枚举
|
||||
typedef enum ItemType
|
||||
{
|
||||
// 父菜单项: 代表菜单中的顶级项或父级项,通常不直接与用户交互,而是作为其他菜单项的容器。
|
||||
PARENTS = 0,
|
||||
// 循环功能项: 代表一种循环执行的功能,在菜单系统中用于循环播放、轮询等操作。
|
||||
LOOP_FUNCTION,
|
||||
// 一次性功能项: 代表仅执行一次的功能,执行后即被标记为完成,不再重复执行。
|
||||
ONCE_FUNCTION,
|
||||
// 开关切换项: 代表菜单中的开关选项,可用于启用或禁用某个功能或设置。
|
||||
SWITCH,
|
||||
// 数据项: 代表菜单中用于显示或设置数据的项,可以是数值、文本等各种形式的数据。
|
||||
DATA
|
||||
} Item_Type;
|
||||
|
||||
//菜单页面类型枚举
|
||||
typedef enum
|
||||
{
|
||||
FIGURE,
|
||||
TEXT
|
||||
}Page_Type;
|
||||
|
||||
// 动画参数
|
||||
typedef struct AnimationParam
|
||||
{
|
||||
// 对话框总时间(单位:毫秒)
|
||||
uint8_t Dialog_AllTime;
|
||||
// 对话框缩放时间(单位:毫秒)
|
||||
uint8_t DialogScale_time;
|
||||
// 对话框初始宽度(单位:像素)
|
||||
uint8_t DialogScale_InitWide;
|
||||
// 对话框初始高度(单位:像素)
|
||||
uint8_t DialogScale_InitHigh;
|
||||
// 当前项宽度(单位:像素)
|
||||
int Item_NowWide;
|
||||
// 当前项高度(单位:行数)
|
||||
int Item_NowLine;
|
||||
// 目标项高度(单位:行数)
|
||||
int Item_TargrtLine;
|
||||
// 目标项宽度(单位:像素)
|
||||
int Item_TargrtWide;
|
||||
// 选项条状态
|
||||
bool OptionState;
|
||||
} Animation_Param;
|
||||
|
||||
typedef struct Page *xpPage;
|
||||
typedef struct Item *xpItem;
|
||||
typedef struct Menu *xpMenu;
|
||||
typedef void (*ItemFunction)(xpItem);
|
||||
|
||||
/**
|
||||
* 定义一个名为Page的结构体类型
|
||||
* 用于表示页面信息
|
||||
*/
|
||||
typedef struct Page {
|
||||
const char *pageName; // 页面名称,使用指针存储
|
||||
uint8_t length; // 页面长度
|
||||
uint8_t id; // 页面ID
|
||||
// 使用内联函数封装成员变量,以提供更高的数据封装性和保护性
|
||||
struct {
|
||||
xpItem parent; // 父级项
|
||||
xpItem head; // 头部项
|
||||
xpItem tail; // 尾部项
|
||||
} item;
|
||||
Page_Type pageType; // 页面类型
|
||||
xpMenu menu; // 页面关联的菜单
|
||||
} xPage;
|
||||
|
||||
// 定义一个名为Item的结构体类型
|
||||
typedef struct Item {
|
||||
const char *itemName; // 结构体成员变量:项目名称,使用const char*类型
|
||||
Item_Type itemType; // 结构体成员变量:项目类型,自定义的Item_Type类型
|
||||
bool switchState; // 结构体成员变量:开关状态,使用bool类型
|
||||
// 封装data指针,以确保数据的完整性
|
||||
struct {
|
||||
int *ptr; // 指向整型数据的指针
|
||||
size_t size; // 指针指向数据的大小,使用size_t类型
|
||||
} data;
|
||||
uint8_t id; // 结构体成员变量:项目ID,使用uint8_t类型
|
||||
// 使用内联函数封装page结构体,以保护成员变量
|
||||
struct {
|
||||
xpPage location; // 页面位置
|
||||
xpPage jumpPage; // 跳转页面
|
||||
} page;
|
||||
xpItem lastItem, nextItem; // 上一个项目和下一个项目的指针
|
||||
ItemFunction itemFunction; // 函数指针,指向一个接受xpItem类型参数的函数
|
||||
Menu_Direction state; // 菜单方向状态
|
||||
uint8_t *logo; // 结构体成员变量:项目关联的图片指针
|
||||
} xItem;
|
||||
|
||||
/**
|
||||
* xMenu结构体定义
|
||||
* 用于表示一个菜单的相关信息
|
||||
*/
|
||||
typedef struct Menu {
|
||||
size_t page_length; // 菜单页面的数量
|
||||
xpItem now_item; // 当前选中的item
|
||||
xpItem old_item; // 上一个选中的item
|
||||
Menu_State menu_state; // 菜单的状态
|
||||
Page_State page_state; // 页面的状态
|
||||
uint8_t BgColor; // 菜单的背景颜色
|
||||
} xMenu;
|
||||
|
||||
#endif
|
||||
179
Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h
Normal file
179
Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Inc/usbd_cdc.h
Normal file
@ -0,0 +1,179 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc.h
|
||||
* @author MCD Application Team
|
||||
* @brief header file for the usbd_cdc.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_CDC_H
|
||||
#define __USB_CDC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup usbd_cdc
|
||||
* @brief This file is the Header file for usbd_cdc.c
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup usbd_cdc_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#define CDC_IN_EP 0x81U /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x01U /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x82U /* EP2 for CDC commands */
|
||||
|
||||
#ifndef CDC_HS_BINTERVAL
|
||||
#define CDC_HS_BINTERVAL 0x10U
|
||||
#endif /* CDC_HS_BINTERVAL */
|
||||
|
||||
#ifndef CDC_FS_BINTERVAL
|
||||
#define CDC_FS_BINTERVAL 0x10U
|
||||
#endif /* CDC_FS_BINTERVAL */
|
||||
|
||||
/* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
|
||||
#define CDC_DATA_HS_MAX_PACKET_SIZE 512U /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_DATA_FS_MAX_PACKET_SIZE 64U /* Endpoint IN & OUT Packet size */
|
||||
#define CDC_CMD_PACKET_SIZE 8U /* Control Endpoint Packet size */
|
||||
|
||||
#define USB_CDC_CONFIG_DESC_SIZ 67U
|
||||
#define CDC_DATA_HS_IN_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_HS_OUT_PACKET_SIZE CDC_DATA_HS_MAX_PACKET_SIZE
|
||||
|
||||
#define CDC_DATA_FS_IN_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
#define CDC_DATA_FS_OUT_PACKET_SIZE CDC_DATA_FS_MAX_PACKET_SIZE
|
||||
|
||||
/*---------------------------------------------------------------------*/
|
||||
/* CDC definitions */
|
||||
/*---------------------------------------------------------------------*/
|
||||
#define CDC_SEND_ENCAPSULATED_COMMAND 0x00U
|
||||
#define CDC_GET_ENCAPSULATED_RESPONSE 0x01U
|
||||
#define CDC_SET_COMM_FEATURE 0x02U
|
||||
#define CDC_GET_COMM_FEATURE 0x03U
|
||||
#define CDC_CLEAR_COMM_FEATURE 0x04U
|
||||
#define CDC_SET_LINE_CODING 0x20U
|
||||
#define CDC_GET_LINE_CODING 0x21U
|
||||
#define CDC_SET_CONTROL_LINE_STATE 0x22U
|
||||
#define CDC_SEND_BREAK 0x23U
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
uint32_t bitrate;
|
||||
uint8_t format;
|
||||
uint8_t paritytype;
|
||||
uint8_t datatype;
|
||||
} USBD_CDC_LineCodingTypeDef;
|
||||
|
||||
typedef struct _USBD_CDC_Itf
|
||||
{
|
||||
int8_t (* Init)(void);
|
||||
int8_t (* DeInit)(void);
|
||||
int8_t (* Control)(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
int8_t (* Receive)(uint8_t *Buf, uint32_t *Len);
|
||||
|
||||
} USBD_CDC_ItfTypeDef;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t data[CDC_DATA_HS_MAX_PACKET_SIZE / 4U]; /* Force 32bits alignment */
|
||||
uint8_t CmdOpCode;
|
||||
uint8_t CmdLength;
|
||||
uint8_t *RxBuffer;
|
||||
uint8_t *TxBuffer;
|
||||
uint32_t RxLength;
|
||||
uint32_t TxLength;
|
||||
|
||||
__IO uint32_t TxState;
|
||||
__IO uint32_t RxState;
|
||||
}
|
||||
USBD_CDC_HandleTypeDef;
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
extern USBD_ClassTypeDef USBD_CDC;
|
||||
#define USBD_CDC_CLASS &USBD_CDC
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USB_CORE_Exported_Functions
|
||||
* @{
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops);
|
||||
|
||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length);
|
||||
|
||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff);
|
||||
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_CDC_H */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -0,0 +1,45 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_if_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header for usbd_cdc_if_template.c file.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CDC_IF_TEMPLATE_H
|
||||
#define __USBD_CDC_IF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
|
||||
extern USBD_CDC_ItfTypeDef USBD_CDC_Template_fops;
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CDC_IF_TEMPLATE_H */
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
945
Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
Normal file
945
Middlewares/ST/STM32_USB_Device_Library/Class/CDC/Src/usbd_cdc.c
Normal file
@ -0,0 +1,945 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the high layer firmware functions to manage the
|
||||
* following functionalities of the USB CDC Class:
|
||||
* - Initialization and Configuration of high and low layer
|
||||
* - Enumeration as CDC Device (and enumeration for each implemented memory interface)
|
||||
* - OUT/IN data transfer
|
||||
* - Command IN transfer (class requests management)
|
||||
* - Error management
|
||||
*
|
||||
* @verbatim
|
||||
*
|
||||
* ===================================================================
|
||||
* CDC Class Driver Description
|
||||
* ===================================================================
|
||||
* This driver manages the "Universal Serial Bus Class Definitions for Communications Devices
|
||||
* Revision 1.2 November 16, 2007" and the sub-protocol specification of "Universal Serial Bus
|
||||
* Communications Class Subclass Specification for PSTN Devices Revision 1.2 February 9, 2007"
|
||||
* This driver implements the following aspects of the specification:
|
||||
* - Device descriptor management
|
||||
* - Configuration descriptor management
|
||||
* - Enumeration as CDC device with 2 data endpoints (IN and OUT) and 1 command endpoint (IN)
|
||||
* - Requests management (as described in section 6.2 in specification)
|
||||
* - Abstract Control Model compliant
|
||||
* - Union Functional collection (using 1 IN endpoint for control)
|
||||
* - Data interface class
|
||||
*
|
||||
* These aspects may be enriched or modified for a specific user application.
|
||||
*
|
||||
* This driver doesn't implement the following aspects of the specification
|
||||
* (but it is possible to manage these features with some modifications on this driver):
|
||||
* - Any class-specific aspect relative to communication classes should be managed by user application.
|
||||
* - All communication classes other than PSTN are not managed
|
||||
*
|
||||
* @endverbatim
|
||||
*
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t cfgidx);
|
||||
|
||||
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum);
|
||||
|
||||
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev);
|
||||
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length);
|
||||
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length);
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
__ALIGN_BEGIN static uint8_t USBD_CDC_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_DEV_QUALIFIER_DESC,
|
||||
USB_DESC_TYPE_DEVICE_QUALIFIER,
|
||||
0x00,
|
||||
0x02,
|
||||
0x00,
|
||||
0x00,
|
||||
0x00,
|
||||
0x40,
|
||||
0x01,
|
||||
0x00,
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/* CDC interface class callbacks structure */
|
||||
USBD_ClassTypeDef USBD_CDC =
|
||||
{
|
||||
USBD_CDC_Init,
|
||||
USBD_CDC_DeInit,
|
||||
USBD_CDC_Setup,
|
||||
NULL, /* EP0_TxSent, */
|
||||
USBD_CDC_EP0_RxReady,
|
||||
USBD_CDC_DataIn,
|
||||
USBD_CDC_DataOut,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
USBD_CDC_GetHSCfgDesc,
|
||||
USBD_CDC_GetFSCfgDesc,
|
||||
USBD_CDC_GetOtherSpeedCfgDesc,
|
||||
USBD_CDC_GetDeviceQualifierDescriptor,
|
||||
};
|
||||
|
||||
/* USB CDC device Configuration Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 0 mA */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
CDC_HS_BINTERVAL, /* bInterval: */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_HS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_HS_MAX_PACKET_SIZE),
|
||||
0x00 /* bInterval: ignore for Bulk transfer */
|
||||
} ;
|
||||
|
||||
|
||||
/* USB CDC device Configuration Descriptor */
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
/*Configuration Descriptor*/
|
||||
0x09, /* bLength: Configuration Descriptor size */
|
||||
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
|
||||
USB_CDC_CONFIG_DESC_SIZ, /* wTotalLength:no of returned bytes */
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interface */
|
||||
0x01, /* bConfigurationValue: Configuration value */
|
||||
0x00, /* iConfiguration: Index of string descriptor describing the configuration */
|
||||
0xC0, /* bmAttributes: self powered */
|
||||
0x32, /* MaxPower 0 mA */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
CDC_FS_BINTERVAL, /* bInterval: */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE),
|
||||
0x00 /* bInterval: ignore for Bulk transfer */
|
||||
} ;
|
||||
|
||||
__ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] __ALIGN_END =
|
||||
{
|
||||
0x09, /* bLength: Configuation Descriptor size */
|
||||
USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION,
|
||||
USB_CDC_CONFIG_DESC_SIZ,
|
||||
0x00,
|
||||
0x02, /* bNumInterfaces: 2 interfaces */
|
||||
0x01, /* bConfigurationValue: */
|
||||
0x04, /* iConfiguration: */
|
||||
0xC0, /* bmAttributes: */
|
||||
0x32, /* MaxPower 100 mA */
|
||||
|
||||
/*Interface Descriptor */
|
||||
0x09, /* bLength: Interface Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: Interface */
|
||||
/* Interface descriptor type */
|
||||
0x00, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x01, /* bNumEndpoints: One endpoints used */
|
||||
0x02, /* bInterfaceClass: Communication Interface Class */
|
||||
0x02, /* bInterfaceSubClass: Abstract Control Model */
|
||||
0x01, /* bInterfaceProtocol: Common AT commands */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Header Functional Descriptor*/
|
||||
0x05, /* bLength: Endpoint Descriptor size */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x00, /* bDescriptorSubtype: Header Func Desc */
|
||||
0x10, /* bcdCDC: spec release number */
|
||||
0x01,
|
||||
|
||||
/*Call Management Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x01, /* bDescriptorSubtype: Call Management Func Desc */
|
||||
0x00, /* bmCapabilities: D0+D1 */
|
||||
0x01, /* bDataInterface: 1 */
|
||||
|
||||
/*ACM Functional Descriptor*/
|
||||
0x04, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x02, /* bDescriptorSubtype: Abstract Control Management desc */
|
||||
0x02, /* bmCapabilities */
|
||||
|
||||
/*Union Functional Descriptor*/
|
||||
0x05, /* bFunctionLength */
|
||||
0x24, /* bDescriptorType: CS_INTERFACE */
|
||||
0x06, /* bDescriptorSubtype: Union func desc */
|
||||
0x00, /* bMasterInterface: Communication class interface */
|
||||
0x01, /* bSlaveInterface0: Data Class Interface */
|
||||
|
||||
/*Endpoint 2 Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_CMD_EP, /* bEndpointAddress */
|
||||
0x03, /* bmAttributes: Interrupt */
|
||||
LOBYTE(CDC_CMD_PACKET_SIZE), /* wMaxPacketSize: */
|
||||
HIBYTE(CDC_CMD_PACKET_SIZE),
|
||||
CDC_FS_BINTERVAL, /* bInterval: */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/*Data class interface descriptor*/
|
||||
0x09, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_INTERFACE, /* bDescriptorType: */
|
||||
0x01, /* bInterfaceNumber: Number of Interface */
|
||||
0x00, /* bAlternateSetting: Alternate setting */
|
||||
0x02, /* bNumEndpoints: Two endpoints used */
|
||||
0x0A, /* bInterfaceClass: CDC */
|
||||
0x00, /* bInterfaceSubClass: */
|
||||
0x00, /* bInterfaceProtocol: */
|
||||
0x00, /* iInterface: */
|
||||
|
||||
/*Endpoint OUT Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_OUT_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
0x40, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00, /* bInterval: ignore for Bulk transfer */
|
||||
|
||||
/*Endpoint IN Descriptor*/
|
||||
0x07, /* bLength: Endpoint Descriptor size */
|
||||
USB_DESC_TYPE_ENDPOINT, /* bDescriptorType: Endpoint */
|
||||
CDC_IN_EP, /* bEndpointAddress */
|
||||
0x02, /* bmAttributes: Bulk */
|
||||
0x40, /* wMaxPacketSize: */
|
||||
0x00,
|
||||
0x00 /* bInterval */
|
||||
};
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Init
|
||||
* Initialize the CDC interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Init(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0U;
|
||||
USBD_CDC_HandleTypeDef *hcdc;
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_HS_IN_PACKET_SIZE);
|
||||
|
||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
|
||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Open EP IN */
|
||||
USBD_LL_OpenEP(pdev, CDC_IN_EP, USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_FS_IN_PACKET_SIZE);
|
||||
|
||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 1U;
|
||||
|
||||
/* Open EP OUT */
|
||||
USBD_LL_OpenEP(pdev, CDC_OUT_EP, USBD_EP_TYPE_BULK,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
|
||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 1U;
|
||||
}
|
||||
/* Open Command IN EP */
|
||||
USBD_LL_OpenEP(pdev, CDC_CMD_EP, USBD_EP_TYPE_INTR, CDC_CMD_PACKET_SIZE);
|
||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->pClassData = USBD_malloc(sizeof(USBD_CDC_HandleTypeDef));
|
||||
|
||||
if (pdev->pClassData == NULL)
|
||||
{
|
||||
ret = 1U;
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Init physical Interface components */
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Init();
|
||||
|
||||
/* Init Xfer states */
|
||||
hcdc->TxState = 0U;
|
||||
hcdc->RxState = 0U;
|
||||
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev, CDC_OUT_EP, hcdc->RxBuffer,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Init
|
||||
* DeInitialize the CDC layer
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: Configuration index
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DeInit(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
uint8_t ret = 0U;
|
||||
|
||||
/* Close EP IN */
|
||||
USBD_LL_CloseEP(pdev, CDC_IN_EP);
|
||||
pdev->ep_in[CDC_IN_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close EP OUT */
|
||||
USBD_LL_CloseEP(pdev, CDC_OUT_EP);
|
||||
pdev->ep_out[CDC_OUT_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* Close Command IN EP */
|
||||
USBD_LL_CloseEP(pdev, CDC_CMD_EP);
|
||||
pdev->ep_in[CDC_CMD_EP & 0xFU].is_used = 0U;
|
||||
|
||||
/* DeInit physical Interface components */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->DeInit();
|
||||
USBD_free(pdev->pClassData);
|
||||
pdev->pClassData = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_Setup
|
||||
* Handle the CDC specific requests
|
||||
* @param pdev: instance
|
||||
* @param req: usb requests
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_Setup(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
uint8_t ifalt = 0U;
|
||||
uint16_t status_info = 0U;
|
||||
uint8_t ret = USBD_OK;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS :
|
||||
if (req->wLength)
|
||||
{
|
||||
if (req->bmRequest & 0x80U)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
req->wLength);
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->CmdOpCode = req->bRequest;
|
||||
hcdc->CmdLength = (uint8_t)req->wLength;
|
||||
|
||||
USBD_CtlPrepareRx(pdev, (uint8_t *)(void *)hcdc->data, req->wLength);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest,
|
||||
(uint8_t *)(void *)req, 0U);
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_STATUS:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&status_info, 2U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_INTERFACE:
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlSendData(pdev, &ifalt, 1U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_INTERFACE:
|
||||
if (pdev->dev_state != USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
ret = USBD_FAIL;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataIn
|
||||
* Data sent on non-control IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataIn(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *)pdev->pClassData;
|
||||
PCD_HandleTypeDef *hpcd = pdev->pData;
|
||||
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if ((pdev->ep_in[epnum].total_length > 0U) && ((pdev->ep_in[epnum].total_length % hpcd->IN_ep[epnum].maxpacket) == 0U))
|
||||
{
|
||||
/* Update the packet total length */
|
||||
pdev->ep_in[epnum].total_length = 0U;
|
||||
|
||||
/* Send ZLP */
|
||||
USBD_LL_Transmit(pdev, epnum, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
hcdc->TxState = 0U;
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_DataOut
|
||||
* Data received on non-control Out endpoint
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint number
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_DataOut(USBD_HandleTypeDef *pdev, uint8_t epnum)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Get the received data length */
|
||||
hcdc->RxLength = USBD_LL_GetRxDataSize(pdev, epnum);
|
||||
|
||||
/* USB data will be immediately processed, this allow next USB traffic being
|
||||
NAKed till the end of the application Xfer */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Receive(hcdc->RxBuffer, &hcdc->RxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_EP0_RxReady
|
||||
* Handle EP0 Rx Ready event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
static uint8_t USBD_CDC_EP0_RxReady(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if ((pdev->pUserData != NULL) && (hcdc->CmdOpCode != 0xFFU))
|
||||
{
|
||||
((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(hcdc->CmdOpCode,
|
||||
(uint8_t *)(void *)hcdc->data,
|
||||
(uint16_t)hcdc->CmdLength);
|
||||
hcdc->CmdOpCode = 0xFFU;
|
||||
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetFSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetFSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CDC_CfgFSDesc);
|
||||
return USBD_CDC_CfgFSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetHSCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetHSCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CDC_CfgHSDesc);
|
||||
return USBD_CDC_CfgHSDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_GetCfgDesc
|
||||
* Return configuration descriptor
|
||||
* @param speed : current device speed
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
static uint8_t *USBD_CDC_GetOtherSpeedCfgDesc(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CDC_OtherSpeedCfgDesc);
|
||||
return USBD_CDC_OtherSpeedCfgDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief DeviceQualifierDescriptor
|
||||
* return Device Qualifier descriptor
|
||||
* @param length : pointer data length
|
||||
* @retval pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_CDC_GetDeviceQualifierDescriptor(uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_CDC_DeviceQualifierDesc);
|
||||
return USBD_CDC_DeviceQualifierDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_RegisterInterface
|
||||
* @param pdev: device instance
|
||||
* @param fops: CD Interface callback
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_RegisterInterface(USBD_HandleTypeDef *pdev,
|
||||
USBD_CDC_ItfTypeDef *fops)
|
||||
{
|
||||
uint8_t ret = USBD_FAIL;
|
||||
|
||||
if (fops != NULL)
|
||||
{
|
||||
pdev->pUserData = fops;
|
||||
ret = USBD_OK;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_SetTxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Tx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetTxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff,
|
||||
uint16_t length)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hcdc->TxBuffer = pbuff;
|
||||
hcdc->TxLength = length;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_SetRxBuffer
|
||||
* @param pdev: device instance
|
||||
* @param pbuff: Rx Buffer
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_SetRxBuffer(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuff)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
hcdc->RxBuffer = pbuff;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_TransmitPacket
|
||||
* Transmit packet on IN endpoint
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_TransmitPacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if (hcdc->TxState == 0U)
|
||||
{
|
||||
/* Tx Transfer in progress */
|
||||
hcdc->TxState = 1U;
|
||||
|
||||
/* Update the packet total length */
|
||||
pdev->ep_in[CDC_IN_EP & 0xFU].total_length = hcdc->TxLength;
|
||||
|
||||
/* Transmit next packet */
|
||||
USBD_LL_Transmit(pdev, CDC_IN_EP, hcdc->TxBuffer,
|
||||
(uint16_t)hcdc->TxLength);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_BUSY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_CDC_ReceivePacket
|
||||
* prepare OUT Endpoint for reception
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
uint8_t USBD_CDC_ReceivePacket(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef *) pdev->pClassData;
|
||||
|
||||
/* Suspend or Resume USB Out process */
|
||||
if (pdev->pClassData != NULL)
|
||||
{
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_HS_OUT_PACKET_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Prepare Out endpoint to receive next packet */
|
||||
USBD_LL_PrepareReceive(pdev,
|
||||
CDC_OUT_EP,
|
||||
hcdc->RxBuffer,
|
||||
CDC_DATA_FS_OUT_PACKET_SIZE);
|
||||
}
|
||||
return USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
return USBD_FAIL;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -0,0 +1,223 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_cdc_if_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief Generic media access Layer.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* BSPDependencies
|
||||
- "stm32xxxxx_{eval}{discovery}{nucleo_144}.c"
|
||||
- "stm32xxxxx_{eval}{discovery}_io.c"
|
||||
EndBSPDependencies */
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_cdc_if_template.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CDC_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CDC_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
static int8_t TEMPLATE_Init(void);
|
||||
static int8_t TEMPLATE_DeInit(void);
|
||||
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length);
|
||||
static int8_t TEMPLATE_Receive(uint8_t *pbuf, uint32_t *Len);
|
||||
|
||||
USBD_CDC_ItfTypeDef USBD_CDC_Template_fops =
|
||||
{
|
||||
TEMPLATE_Init,
|
||||
TEMPLATE_DeInit,
|
||||
TEMPLATE_Control,
|
||||
TEMPLATE_Receive
|
||||
};
|
||||
|
||||
USBD_CDC_LineCodingTypeDef linecoding =
|
||||
{
|
||||
115200, /* baud rate*/
|
||||
0x00, /* stop bits-1*/
|
||||
0x00, /* parity - none*/
|
||||
0x08 /* nb. of bits 8*/
|
||||
};
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Init
|
||||
* Initializes the CDC media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Init(void)
|
||||
{
|
||||
/*
|
||||
Add your initialization code here
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_DeInit
|
||||
* DeInitializes the CDC media low layer
|
||||
* @param None
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_DeInit(void)
|
||||
{
|
||||
/*
|
||||
Add your deinitialization code here
|
||||
*/
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Control
|
||||
* Manage the CDC class requests
|
||||
* @param Cmd: Command code
|
||||
* @param Buf: Buffer containing command data (request parameters)
|
||||
* @param Len: Number of data to be sent (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Control(uint8_t cmd, uint8_t *pbuf, uint16_t length)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case CDC_SEND_ENCAPSULATED_COMMAND:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_ENCAPSULATED_RESPONSE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_CLEAR_COMM_FEATURE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_LINE_CODING:
|
||||
linecoding.bitrate = (uint32_t)(pbuf[0] | (pbuf[1] << 8) | \
|
||||
(pbuf[2] << 16) | (pbuf[3] << 24));
|
||||
linecoding.format = pbuf[4];
|
||||
linecoding.paritytype = pbuf[5];
|
||||
linecoding.datatype = pbuf[6];
|
||||
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_GET_LINE_CODING:
|
||||
pbuf[0] = (uint8_t)(linecoding.bitrate);
|
||||
pbuf[1] = (uint8_t)(linecoding.bitrate >> 8);
|
||||
pbuf[2] = (uint8_t)(linecoding.bitrate >> 16);
|
||||
pbuf[3] = (uint8_t)(linecoding.bitrate >> 24);
|
||||
pbuf[4] = linecoding.format;
|
||||
pbuf[5] = linecoding.paritytype;
|
||||
pbuf[6] = linecoding.datatype;
|
||||
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SET_CONTROL_LINE_STATE:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
case CDC_SEND_BREAK:
|
||||
/* Add your code here */
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief TEMPLATE_Receive
|
||||
* Data received over USB OUT endpoint are sent over CDC interface
|
||||
* through this function.
|
||||
*
|
||||
* @note
|
||||
* This function will issue a NAK packet on any OUT packet received on
|
||||
* USB endpoint untill exiting this function. If you exit this function
|
||||
* before transfer is complete on CDC interface (ie. using DMA controller)
|
||||
* it will result in receiving more data while previous ones are still
|
||||
* not sent.
|
||||
*
|
||||
* @param Buf: Buffer of data to be received
|
||||
* @param Len: Number of data received (in bytes)
|
||||
* @retval Result of the operation: USBD_OK if all operations are OK else USBD_FAIL
|
||||
*/
|
||||
static int8_t TEMPLATE_Receive(uint8_t *Buf, uint32_t *Len)
|
||||
{
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
@ -0,0 +1,162 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_conf_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for the usbd_conf_template.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CONF_TEMPLATE_H
|
||||
#define __USBD_CONF_TEMPLATE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32fxxx.h" /* replace 'stm32xxx' with your HAL driver header filename, ex: stm32f4xx.h */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF
|
||||
* @brief USB device low level driver configuration file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#define USBD_MAX_NUM_INTERFACES 1U
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||
#define USBD_MAX_STR_DESC_SIZ 0x100U
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||
#define USBD_SELF_POWERED 1U
|
||||
#define USBD_DEBUG_LEVEL 2U
|
||||
|
||||
/* MSC Class Config */
|
||||
#define MSC_MEDIA_PACKET 8192U
|
||||
|
||||
/* CDC Class Config */
|
||||
#define USBD_CDC_INTERVAL 2000U
|
||||
|
||||
/* DFU Class Config */
|
||||
#define USBD_DFU_MAX_ITF_NUM 1U
|
||||
#define USBD_DFU_XFERS_IZE 1024U
|
||||
|
||||
/* AUDIO Class Config */
|
||||
#define USBD_AUDIO_FREQ 22100U
|
||||
|
||||
/** @defgroup USBD_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Memory management macros */
|
||||
#define USBD_malloc malloc
|
||||
#define USBD_free free
|
||||
#define USBD_memset memset
|
||||
#define USBD_memcpy memcpy
|
||||
|
||||
/* DEBUG macros */
|
||||
#if (USBD_DEBUG_LEVEL > 0U)
|
||||
#define USBD_UsrLog(...) do { \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define USBD_UsrLog(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 1U)
|
||||
|
||||
#define USBD_ErrLog(...) do { \
|
||||
printf("ERROR: ") ; \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define USBD_ErrLog(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
#if (USBD_DEBUG_LEVEL > 2U)
|
||||
#define USBD_DbgLog(...) do { \
|
||||
printf("DEBUG : ") ; \
|
||||
printf(__VA_ARGS__); \
|
||||
printf("\n"); \
|
||||
} while (0)
|
||||
#else
|
||||
#define USBD_DbgLog(...) do {} while (0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CONF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CONF_TEMPLATE_H */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
161
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h
Normal file
161
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_core.h
Normal file
@ -0,0 +1,161 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_core.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for usbd_core.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_CORE_H
|
||||
#define __USBD_CORE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_conf.h"
|
||||
#include "usbd_def.h"
|
||||
#include "usbd_ioreq.h"
|
||||
#include "usbd_ctlreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief This file is the Header file for usbd_core.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
#ifndef USBD_DEBUG_LEVEL
|
||||
#define USBD_DEBUG_LEVEL 0U
|
||||
#endif /* USBD_DEBUG_LEVEL */
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
#define USBD_SOF USBD_LL_SOF
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev, USBD_DescriptorsTypeDef *pdesc, uint8_t id);
|
||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass);
|
||||
|
||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup);
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev, uint8_t epnum, uint8_t *pdata);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev, USBD_SpeedTypeDef speed);
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev);
|
||||
|
||||
/* USBD Low Level Driver */
|
||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev);
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t ep_type,
|
||||
uint16_t ep_mps);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev, uint8_t dev_addr);
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size);
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr,
|
||||
uint8_t *pbuf,
|
||||
uint16_t size);
|
||||
|
||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
void USBD_LL_Delay(uint32_t Delay);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_CORE_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
|
||||
|
||||
105
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h
Normal file
105
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ctlreq.h
Normal file
@ -0,0 +1,105 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_req.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for the usbd_req.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USB_REQUEST_H
|
||||
#define __USB_REQUEST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ
|
||||
* @brief header file for the usbd_req.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
|
||||
void USBD_CtlError(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
|
||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata);
|
||||
|
||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USB_REQUEST_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
348
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
Normal file
348
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_def.h
Normal file
@ -0,0 +1,348 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_def.h
|
||||
* @author MCD Application Team
|
||||
* @brief General defines for the usb device library
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_DEF_H
|
||||
#define __USBD_DEF_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_conf.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DEF
|
||||
* @brief general defines for the usb device library file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USB_DEF_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL 0U
|
||||
#endif /* NULL */
|
||||
|
||||
#ifndef USBD_MAX_NUM_INTERFACES
|
||||
#define USBD_MAX_NUM_INTERFACES 1U
|
||||
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
||||
|
||||
#ifndef USBD_MAX_NUM_CONFIGURATION
|
||||
#define USBD_MAX_NUM_CONFIGURATION 1U
|
||||
#endif /* USBD_MAX_NUM_CONFIGURATION */
|
||||
|
||||
#ifndef USBD_LPM_ENABLED
|
||||
#define USBD_LPM_ENABLED 0U
|
||||
#endif /* USBD_LPM_ENABLED */
|
||||
|
||||
#ifndef USBD_SELF_POWERED
|
||||
#define USBD_SELF_POWERED 1U
|
||||
#endif /*USBD_SELF_POWERED */
|
||||
|
||||
#ifndef USBD_SUPPORT_USER_STRING_DESC
|
||||
#define USBD_SUPPORT_USER_STRING_DESC 0U
|
||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
#define USB_LEN_DEV_QUALIFIER_DESC 0x0AU
|
||||
#define USB_LEN_DEV_DESC 0x12U
|
||||
#define USB_LEN_CFG_DESC 0x09U
|
||||
#define USB_LEN_IF_DESC 0x09U
|
||||
#define USB_LEN_EP_DESC 0x07U
|
||||
#define USB_LEN_OTG_DESC 0x03U
|
||||
#define USB_LEN_LANGID_STR_DESC 0x04U
|
||||
#define USB_LEN_OTHER_SPEED_DESC_SIZ 0x09U
|
||||
|
||||
#define USBD_IDX_LANGID_STR 0x00U
|
||||
#define USBD_IDX_MFC_STR 0x01U
|
||||
#define USBD_IDX_PRODUCT_STR 0x02U
|
||||
#define USBD_IDX_SERIAL_STR 0x03U
|
||||
#define USBD_IDX_CONFIG_STR 0x04U
|
||||
#define USBD_IDX_INTERFACE_STR 0x05U
|
||||
|
||||
#define USB_REQ_TYPE_STANDARD 0x00U
|
||||
#define USB_REQ_TYPE_CLASS 0x20U
|
||||
#define USB_REQ_TYPE_VENDOR 0x40U
|
||||
#define USB_REQ_TYPE_MASK 0x60U
|
||||
|
||||
#define USB_REQ_RECIPIENT_DEVICE 0x00U
|
||||
#define USB_REQ_RECIPIENT_INTERFACE 0x01U
|
||||
#define USB_REQ_RECIPIENT_ENDPOINT 0x02U
|
||||
#define USB_REQ_RECIPIENT_MASK 0x03U
|
||||
|
||||
#define USB_REQ_GET_STATUS 0x00U
|
||||
#define USB_REQ_CLEAR_FEATURE 0x01U
|
||||
#define USB_REQ_SET_FEATURE 0x03U
|
||||
#define USB_REQ_SET_ADDRESS 0x05U
|
||||
#define USB_REQ_GET_DESCRIPTOR 0x06U
|
||||
#define USB_REQ_SET_DESCRIPTOR 0x07U
|
||||
#define USB_REQ_GET_CONFIGURATION 0x08U
|
||||
#define USB_REQ_SET_CONFIGURATION 0x09U
|
||||
#define USB_REQ_GET_INTERFACE 0x0AU
|
||||
#define USB_REQ_SET_INTERFACE 0x0BU
|
||||
#define USB_REQ_SYNCH_FRAME 0x0CU
|
||||
|
||||
#define USB_DESC_TYPE_DEVICE 0x01U
|
||||
#define USB_DESC_TYPE_CONFIGURATION 0x02U
|
||||
#define USB_DESC_TYPE_STRING 0x03U
|
||||
#define USB_DESC_TYPE_INTERFACE 0x04U
|
||||
#define USB_DESC_TYPE_ENDPOINT 0x05U
|
||||
#define USB_DESC_TYPE_DEVICE_QUALIFIER 0x06U
|
||||
#define USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION 0x07U
|
||||
#define USB_DESC_TYPE_BOS 0x0FU
|
||||
|
||||
#define USB_CONFIG_REMOTE_WAKEUP 0x02U
|
||||
#define USB_CONFIG_SELF_POWERED 0x01U
|
||||
|
||||
#define USB_FEATURE_EP_HALT 0x00U
|
||||
#define USB_FEATURE_REMOTE_WAKEUP 0x01U
|
||||
#define USB_FEATURE_TEST_MODE 0x02U
|
||||
|
||||
#define USB_DEVICE_CAPABITY_TYPE 0x10U
|
||||
|
||||
#define USB_HS_MAX_PACKET_SIZE 512U
|
||||
#define USB_FS_MAX_PACKET_SIZE 64U
|
||||
#define USB_MAX_EP0_SIZE 64U
|
||||
|
||||
/* Device Status */
|
||||
#define USBD_STATE_DEFAULT 0x01U
|
||||
#define USBD_STATE_ADDRESSED 0x02U
|
||||
#define USBD_STATE_CONFIGURED 0x03U
|
||||
#define USBD_STATE_SUSPENDED 0x04U
|
||||
|
||||
|
||||
/* EP0 State */
|
||||
#define USBD_EP0_IDLE 0x00U
|
||||
#define USBD_EP0_SETUP 0x01U
|
||||
#define USBD_EP0_DATA_IN 0x02U
|
||||
#define USBD_EP0_DATA_OUT 0x03U
|
||||
#define USBD_EP0_STATUS_IN 0x04U
|
||||
#define USBD_EP0_STATUS_OUT 0x05U
|
||||
#define USBD_EP0_STALL 0x06U
|
||||
|
||||
#define USBD_EP_TYPE_CTRL 0x00U
|
||||
#define USBD_EP_TYPE_ISOC 0x01U
|
||||
#define USBD_EP_TYPE_BULK 0x02U
|
||||
#define USBD_EP_TYPE_INTR 0x03U
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef struct usb_setup_req
|
||||
{
|
||||
uint8_t bmRequest;
|
||||
uint8_t bRequest;
|
||||
uint16_t wValue;
|
||||
uint16_t wIndex;
|
||||
uint16_t wLength;
|
||||
} USBD_SetupReqTypedef;
|
||||
|
||||
struct _USBD_HandleTypeDef;
|
||||
|
||||
typedef struct _Device_cb
|
||||
{
|
||||
uint8_t (*Init)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
uint8_t (*DeInit)(struct _USBD_HandleTypeDef *pdev, uint8_t cfgidx);
|
||||
/* Control Endpoints*/
|
||||
uint8_t (*Setup)(struct _USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req);
|
||||
uint8_t (*EP0_TxSent)(struct _USBD_HandleTypeDef *pdev);
|
||||
uint8_t (*EP0_RxReady)(struct _USBD_HandleTypeDef *pdev);
|
||||
/* Class Specific Endpoints*/
|
||||
uint8_t (*DataIn)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t (*DataOut)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t (*SOF)(struct _USBD_HandleTypeDef *pdev);
|
||||
uint8_t (*IsoINIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
uint8_t (*IsoOUTIncomplete)(struct _USBD_HandleTypeDef *pdev, uint8_t epnum);
|
||||
|
||||
uint8_t *(*GetHSConfigDescriptor)(uint16_t *length);
|
||||
uint8_t *(*GetFSConfigDescriptor)(uint16_t *length);
|
||||
uint8_t *(*GetOtherSpeedConfigDescriptor)(uint16_t *length);
|
||||
uint8_t *(*GetDeviceQualifierDescriptor)(uint16_t *length);
|
||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||
uint8_t *(*GetUsrStrDescriptor)(struct _USBD_HandleTypeDef *pdev, uint8_t index, uint16_t *length);
|
||||
#endif
|
||||
|
||||
} USBD_ClassTypeDef;
|
||||
|
||||
/* Following USB Device Speed */
|
||||
typedef enum
|
||||
{
|
||||
USBD_SPEED_HIGH = 0U,
|
||||
USBD_SPEED_FULL = 1U,
|
||||
USBD_SPEED_LOW = 2U,
|
||||
} USBD_SpeedTypeDef;
|
||||
|
||||
/* Following USB Device status */
|
||||
typedef enum
|
||||
{
|
||||
USBD_OK = 0U,
|
||||
USBD_BUSY,
|
||||
USBD_FAIL,
|
||||
} USBD_StatusTypeDef;
|
||||
|
||||
/* USB Device descriptors structure */
|
||||
typedef struct
|
||||
{
|
||||
uint8_t *(*GetDeviceDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetLangIDStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetManufacturerStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetProductStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetSerialStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetConfigurationStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *(*GetInterfaceStrDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#if (USBD_LPM_ENABLED == 1U)
|
||||
uint8_t *(*GetBOSDescriptor)(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#endif
|
||||
} USBD_DescriptorsTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct
|
||||
{
|
||||
uint32_t status;
|
||||
uint32_t is_used;
|
||||
uint32_t total_length;
|
||||
uint32_t rem_length;
|
||||
uint32_t maxpacket;
|
||||
} USBD_EndpointTypeDef;
|
||||
|
||||
/* USB Device handle structure */
|
||||
typedef struct _USBD_HandleTypeDef
|
||||
{
|
||||
uint8_t id;
|
||||
uint32_t dev_config;
|
||||
uint32_t dev_default_config;
|
||||
uint32_t dev_config_status;
|
||||
USBD_SpeedTypeDef dev_speed;
|
||||
USBD_EndpointTypeDef ep_in[16];
|
||||
USBD_EndpointTypeDef ep_out[16];
|
||||
uint32_t ep0_state;
|
||||
uint32_t ep0_data_len;
|
||||
uint8_t dev_state;
|
||||
uint8_t dev_old_state;
|
||||
uint8_t dev_address;
|
||||
uint8_t dev_connection_status;
|
||||
uint8_t dev_test_mode;
|
||||
uint32_t dev_remote_wakeup;
|
||||
|
||||
USBD_SetupReqTypedef request;
|
||||
USBD_DescriptorsTypeDef *pDesc;
|
||||
USBD_ClassTypeDef *pClass;
|
||||
void *pClassData;
|
||||
void *pUserData;
|
||||
void *pData;
|
||||
} USBD_HandleTypeDef;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
#define SWAPBYTE(addr) (((uint16_t)(*((uint8_t *)(addr)))) + \
|
||||
(((uint16_t)(*(((uint8_t *)(addr)) + 1U))) << 8U))
|
||||
|
||||
#define LOBYTE(x) ((uint8_t)((x) & 0x00FFU))
|
||||
#define HIBYTE(x) ((uint8_t)(((x) & 0xFF00U) >> 8U))
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
|
||||
#if defined ( __GNUC__ )
|
||||
#ifndef __weak
|
||||
#define __weak __attribute__((weak))
|
||||
#endif /* __weak */
|
||||
#ifndef __packed
|
||||
#define __packed __attribute__((__packed__))
|
||||
#endif /* __packed */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/* In HS mode and when the DMA is used, all variables and data structures dealing
|
||||
with the DMA during the transaction process should be 4-bytes aligned */
|
||||
|
||||
#if defined ( __GNUC__ ) && !defined (__CC_ARM) /* GNU Compiler */
|
||||
#ifndef __ALIGN_END
|
||||
#define __ALIGN_END __attribute__ ((aligned (4U)))
|
||||
#endif /* __ALIGN_END */
|
||||
#ifndef __ALIGN_BEGIN
|
||||
#define __ALIGN_BEGIN
|
||||
#endif /* __ALIGN_BEGIN */
|
||||
#else
|
||||
#ifndef __ALIGN_END
|
||||
#define __ALIGN_END
|
||||
#endif /* __ALIGN_END */
|
||||
#ifndef __ALIGN_BEGIN
|
||||
#if defined (__CC_ARM) /* ARM Compiler */
|
||||
#define __ALIGN_BEGIN __align(4U)
|
||||
#elif defined (__ICCARM__) /* IAR Compiler */
|
||||
#define __ALIGN_BEGIN
|
||||
#endif /* __CC_ARM */
|
||||
#endif /* __ALIGN_BEGIN */
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_DEF_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_DEF_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -0,0 +1,41 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_desc_template.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header for usbd_desc_template.c module
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_DESC_TEMPLATE_H
|
||||
#define __USBD_DESC_TEMPLATE_H
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
#define DEVICE_ID1 (0x1FFF7A10)
|
||||
#define DEVICE_ID2 (0x1FFF7A14)
|
||||
#define DEVICE_ID3 (0x1FFF7A18)
|
||||
|
||||
#define USB_SIZ_STRING_SERIAL 0x1A
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* Exported functions ------------------------------------------------------- */
|
||||
extern USBD_DescriptorsTypeDef XXX_Desc; /* Replace 'XXX_Desc' with your active USB device class, ex: HID_Desc */
|
||||
|
||||
#endif /* __USBD_DESC_TEMPLATE_H*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
119
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h
Normal file
119
Middlewares/ST/STM32_USB_Device_Library/Core/Inc/usbd_ioreq.h
Normal file
@ -0,0 +1,119 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ioreq.h
|
||||
* @author MCD Application Team
|
||||
* @brief Header file for the usbd_ioreq.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __USBD_IOREQ_H
|
||||
#define __USBD_IOREQ_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_def.h"
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ
|
||||
* @brief header file for the usbd_ioreq.c file
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Defines
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Types
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
|
||||
* @{
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf,
|
||||
uint16_t len);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev);
|
||||
|
||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __USBD_IOREQ_H */
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -0,0 +1,201 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_conf_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief USB Device configuration and interface file
|
||||
* This template should be copied to the user folder,
|
||||
* renamed and customized following user needs.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
/**
|
||||
* @brief Initializes the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-Initializes the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Starts the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Start(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Stops the Low Level portion of the Device driver.
|
||||
* @param pdev: Device handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Stop(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Opens an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param ep_type: Endpoint Type
|
||||
* @param ep_mps: Endpoint Max Packet Size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_OpenEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t ep_type, uint16_t ep_mps)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Closes an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_CloseEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Flushes an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_FlushEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets a Stall condition on an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_StallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears a Stall condition on an endpoint of the Low Level Driver.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_ClearStallEP(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns Stall condition.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Stall (1: Yes, 0: No)
|
||||
*/
|
||||
uint8_t USBD_LL_IsStallEP(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assigns a USB address to the device.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetUSBAddress(USBD_HandleTypeDef *pdev,
|
||||
uint8_t dev_addr)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Transmits data over an endpoint.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param pbuf: Pointer to data to be sent
|
||||
* @param size: Data size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_Transmit(USBD_HandleTypeDef *pdev, uint8_t ep_addr,
|
||||
uint8_t *pbuf, uint16_t size)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Prepares an endpoint for reception.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @param pbuf: Pointer to data to be received
|
||||
* @param size: Data size
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_PrepareReceive(USBD_HandleTypeDef *pdev,
|
||||
uint8_t ep_addr, uint8_t *pbuf,
|
||||
uint16_t size)
|
||||
{
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the last transferred packet size.
|
||||
* @param pdev: Device handle
|
||||
* @param ep_addr: Endpoint Number
|
||||
* @retval Recived Data Size
|
||||
*/
|
||||
uint32_t USBD_LL_GetRxDataSize(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return 0U;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delays routine for the USB Device Library.
|
||||
* @param Delay: Delay in ms
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_LL_Delay(uint32_t Delay)
|
||||
{
|
||||
}
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
611
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
Normal file
611
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_core.c
Normal file
@ -0,0 +1,611 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_core.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides all the USBD core functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
|
||||
/** @addtogroup STM32_USBD_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE
|
||||
* @brief usbd core module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_CORE_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_Init
|
||||
* Initializes the device stack and load the class driver
|
||||
* @param pdev: device instance
|
||||
* @param pdesc: Descriptor structure address
|
||||
* @param id: Low level core index
|
||||
* @retval None
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Init(USBD_HandleTypeDef *pdev,
|
||||
USBD_DescriptorsTypeDef *pdesc, uint8_t id)
|
||||
{
|
||||
/* Check whether the USB Host handle is valid */
|
||||
if (pdev == NULL)
|
||||
{
|
||||
#if (USBD_DEBUG_LEVEL > 1U)
|
||||
USBD_ErrLog("Invalid Device handle");
|
||||
#endif
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
/* Unlink previous class*/
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
pdev->pClass = NULL;
|
||||
}
|
||||
|
||||
/* Assign USBD Descriptors */
|
||||
if (pdesc != NULL)
|
||||
{
|
||||
pdev->pDesc = pdesc;
|
||||
}
|
||||
|
||||
/* Set Device initial State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->id = id;
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_Init(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DeInit
|
||||
* Re-Initialize th device library
|
||||
* @param pdev: device instance
|
||||
* @retval status: status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_DeInit(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set Default State */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
|
||||
/* Initialize low level driver */
|
||||
USBD_LL_DeInit(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_RegisterClass
|
||||
* Link class driver to Device Core.
|
||||
* @param pDevice : Device Handle
|
||||
* @param pclass: Class handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RegisterClass(USBD_HandleTypeDef *pdev, USBD_ClassTypeDef *pclass)
|
||||
{
|
||||
USBD_StatusTypeDef status = USBD_OK;
|
||||
if (pclass != NULL)
|
||||
{
|
||||
/* link the class to the USB Device handle */
|
||||
pdev->pClass = pclass;
|
||||
status = USBD_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if (USBD_DEBUG_LEVEL > 1U)
|
||||
USBD_ErrLog("Invalid Class handle");
|
||||
#endif
|
||||
status = USBD_FAIL;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Start
|
||||
* Start the USB Device Core.
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Start(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Start the low level driver */
|
||||
USBD_LL_Start(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Stop
|
||||
* Stop the USB Device Core.
|
||||
* @param pdev: Device Handle
|
||||
* @retval USBD Status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_Stop(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
/* Stop the low level driver */
|
||||
USBD_LL_Stop(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_RunTestMode
|
||||
* Launch test mode process
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_RunTestMode(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetClassConfig
|
||||
* Configure device and start the interface
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_SetClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_FAIL;
|
||||
|
||||
if (pdev->pClass != NULL)
|
||||
{
|
||||
/* Set configuration and Start the Class*/
|
||||
if (pdev->pClass->Init(pdev, cfgidx) == 0U)
|
||||
{
|
||||
ret = USBD_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrClassConfig
|
||||
* Clear current configuration
|
||||
* @param pdev: device instance
|
||||
* @param cfgidx: configuration index
|
||||
* @retval status: USBD_StatusTypeDef
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_ClrClassConfig(USBD_HandleTypeDef *pdev, uint8_t cfgidx)
|
||||
{
|
||||
/* Clear configuration and De-initialize the Class process*/
|
||||
pdev->pClass->DeInit(pdev, cfgidx);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetupStage
|
||||
* Handle the setup stage
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetupStage(USBD_HandleTypeDef *pdev, uint8_t *psetup)
|
||||
{
|
||||
USBD_ParseSetupRequest(&pdev->request, psetup);
|
||||
|
||||
pdev->ep0_state = USBD_EP0_SETUP;
|
||||
|
||||
pdev->ep0_data_len = pdev->request.wLength;
|
||||
|
||||
switch (pdev->request.bmRequest & 0x1FU)
|
||||
{
|
||||
case USB_REQ_RECIPIENT_DEVICE:
|
||||
USBD_StdDevReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
case USB_REQ_RECIPIENT_INTERFACE:
|
||||
USBD_StdItfReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
case USB_REQ_RECIPIENT_ENDPOINT:
|
||||
USBD_StdEPReq(pdev, &pdev->request);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_LL_StallEP(pdev, (pdev->request.bmRequest & 0x80U));
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataOutStage
|
||||
* Handle data OUT stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataOutStage(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
|
||||
if (epnum == 0U)
|
||||
{
|
||||
pep = &pdev->ep_out[0];
|
||||
|
||||
if (pdev->ep0_state == USBD_EP0_DATA_OUT)
|
||||
{
|
||||
if (pep->rem_length > pep->maxpacket)
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueRx(pdev, pdata,
|
||||
(uint16_t)MIN(pep->rem_length, pep->maxpacket));
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pdev->pClass->EP0_RxReady != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->EP0_RxReady(pdev);
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pdev->ep0_state == USBD_EP0_STATUS_OUT)
|
||||
{
|
||||
/*
|
||||
* STATUS PHASE completed, update ep0_state to idle
|
||||
*/
|
||||
pdev->ep0_state = USBD_EP0_IDLE;
|
||||
USBD_LL_StallEP(pdev, 0U);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((pdev->pClass->DataOut != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataOut(pdev, epnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* should never be in this condition */
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DataInStage
|
||||
* Handle data in stage
|
||||
* @param pdev: device instance
|
||||
* @param epnum: endpoint index
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DataInStage(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum, uint8_t *pdata)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
|
||||
if (epnum == 0U)
|
||||
{
|
||||
pep = &pdev->ep_in[0];
|
||||
|
||||
if (pdev->ep0_state == USBD_EP0_DATA_IN)
|
||||
{
|
||||
if (pep->rem_length > pep->maxpacket)
|
||||
{
|
||||
pep->rem_length -= pep->maxpacket;
|
||||
|
||||
USBD_CtlContinueSendData(pdev, pdata, (uint16_t)pep->rem_length);
|
||||
|
||||
/* Prepare endpoint for premature end of transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* last packet is MPS multiple, so send ZLP packet */
|
||||
if ((pep->total_length % pep->maxpacket == 0U) &&
|
||||
(pep->total_length >= pep->maxpacket) &&
|
||||
(pep->total_length < pdev->ep0_data_len))
|
||||
{
|
||||
USBD_CtlContinueSendData(pdev, NULL, 0U);
|
||||
pdev->ep0_data_len = 0U;
|
||||
|
||||
/* Prepare endpoint for premature end of transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pdev->pClass->EP0_TxSent != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->EP0_TxSent(pdev);
|
||||
}
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
USBD_CtlReceiveStatus(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pdev->ep0_state == USBD_EP0_STATUS_IN) ||
|
||||
(pdev->ep0_state == USBD_EP0_IDLE))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
}
|
||||
}
|
||||
|
||||
if (pdev->dev_test_mode == 1U)
|
||||
{
|
||||
USBD_RunTestMode(pdev);
|
||||
pdev->dev_test_mode = 0U;
|
||||
}
|
||||
}
|
||||
else if ((pdev->pClass->DataIn != NULL) &&
|
||||
(pdev->dev_state == USBD_STATE_CONFIGURED))
|
||||
{
|
||||
pdev->pClass->DataIn(pdev, epnum);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* should never be in this condition */
|
||||
return USBD_FAIL;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Reset(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Open EP0 OUT */
|
||||
USBD_LL_OpenEP(pdev, 0x00U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||
pdev->ep_out[0x00U & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->ep_out[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Open EP0 IN */
|
||||
USBD_LL_OpenEP(pdev, 0x80U, USBD_EP_TYPE_CTRL, USB_MAX_EP0_SIZE);
|
||||
pdev->ep_in[0x80U & 0xFU].is_used = 1U;
|
||||
|
||||
pdev->ep_in[0].maxpacket = USB_MAX_EP0_SIZE;
|
||||
|
||||
/* Upon Reset call user call back */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->ep0_state = USBD_EP0_IDLE;
|
||||
pdev->dev_config = 0U;
|
||||
pdev->dev_remote_wakeup = 0U;
|
||||
|
||||
if (pdev->pClassData)
|
||||
{
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_LL_Reset
|
||||
* Handle Reset event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_SetSpeed(USBD_HandleTypeDef *pdev,
|
||||
USBD_SpeedTypeDef speed)
|
||||
{
|
||||
pdev->dev_speed = speed;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Suspend
|
||||
* Handle Suspend event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Suspend(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
pdev->dev_old_state = pdev->dev_state;
|
||||
pdev->dev_state = USBD_STATE_SUSPENDED;
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_Resume
|
||||
* Handle Resume event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_Resume(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if (pdev->dev_state == USBD_STATE_SUSPENDED)
|
||||
{
|
||||
pdev->dev_state = pdev->dev_old_state;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SOF
|
||||
* Handle SOF event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
|
||||
USBD_StatusTypeDef USBD_LL_SOF(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
if (pdev->pClass->SOF != NULL)
|
||||
{
|
||||
pdev->pClass->SOF(pdev);
|
||||
}
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoINIncomplete
|
||||
* Handle iso in incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoINIncomplete(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
/* Prevent unused arguments compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_IsoOUTIncomplete
|
||||
* Handle iso out incomplete event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_IsoOUTIncomplete(USBD_HandleTypeDef *pdev,
|
||||
uint8_t epnum)
|
||||
{
|
||||
/* Prevent unused arguments compilation warning */
|
||||
UNUSED(pdev);
|
||||
UNUSED(epnum);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevConnected
|
||||
* Handle device connection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevConnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Prevent unused argument compilation warning */
|
||||
UNUSED(pdev);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_DevDisconnected
|
||||
* Handle device disconnection event
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_LL_DevDisconnected(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Free Class Resources */
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
pdev->pClass->DeInit(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
|
||||
918
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
Normal file
918
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
Normal file
@ -0,0 +1,918 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_req.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the standard USB requests following chapter 9.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ctlreq.h"
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
|
||||
/** @addtogroup STM32_USBD_STATE_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ
|
||||
* @brief USB standard requests module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_REQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req);
|
||||
|
||||
static uint8_t USBD_GetLen(uint8_t *buf);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_REQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_StdDevReq
|
||||
* Handle standard usb device requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdDevReq(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
case USB_REQ_TYPE_VENDOR:
|
||||
pdev->pClass->Setup(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_GET_DESCRIPTOR:
|
||||
USBD_GetDescriptor(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_ADDRESS:
|
||||
USBD_SetAddress(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_CONFIGURATION:
|
||||
USBD_SetConfig(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_CONFIGURATION:
|
||||
USBD_GetConfig(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_STATUS:
|
||||
USBD_GetStatus(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_SET_FEATURE:
|
||||
USBD_SetFeature(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
USBD_ClrFeature(pdev, req);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdItfReq
|
||||
* Handle standard usb interface requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdItfReq(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
case USB_REQ_TYPE_VENDOR:
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_DEFAULT:
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
|
||||
if (LOBYTE(req->wIndex) <= USBD_MAX_NUM_INTERFACES)
|
||||
{
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
||||
|
||||
if ((req->wLength == 0U) && (ret == USBD_OK))
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_StdEPReq
|
||||
* Handle standard usb endpoint requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_EndpointTypeDef *pep;
|
||||
uint8_t ep_addr;
|
||||
USBD_StatusTypeDef ret = USBD_OK;
|
||||
ep_addr = LOBYTE(req->wIndex);
|
||||
|
||||
switch (req->bmRequest & USB_REQ_TYPE_MASK)
|
||||
{
|
||||
case USB_REQ_TYPE_CLASS:
|
||||
case USB_REQ_TYPE_VENDOR:
|
||||
pdev->pClass->Setup(pdev, req);
|
||||
break;
|
||||
|
||||
case USB_REQ_TYPE_STANDARD:
|
||||
/* Check if it is a class request */
|
||||
if ((req->bmRequest & 0x60U) == 0x20U)
|
||||
{
|
||||
ret = (USBD_StatusTypeDef)pdev->pClass->Setup(pdev, req);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
switch (req->bRequest)
|
||||
{
|
||||
case USB_REQ_SET_FEATURE:
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, ep_addr);
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr != 0x00U) &&
|
||||
(ep_addr != 0x80U) && (req->wLength == 0x00U))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, ep_addr);
|
||||
}
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_CLEAR_FEATURE:
|
||||
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
|
||||
{
|
||||
USBD_LL_StallEP(pdev, ep_addr);
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_EP_HALT)
|
||||
{
|
||||
if ((ep_addr & 0x7FU) != 0x00U)
|
||||
{
|
||||
USBD_LL_ClearStallEP(pdev, ep_addr);
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_REQ_GET_STATUS:
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
|
||||
&pdev->ep_out[ep_addr & 0x7FU];
|
||||
|
||||
pep->status = 0x0000U;
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U);
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if ((ep_addr & 0x80U) == 0x80U)
|
||||
{
|
||||
if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
|
||||
&pdev->ep_out[ep_addr & 0x7FU];
|
||||
|
||||
if ((ep_addr == 0x00U) || (ep_addr == 0x80U))
|
||||
{
|
||||
pep->status = 0x0000U;
|
||||
}
|
||||
else if (USBD_LL_IsStallEP(pdev, ep_addr))
|
||||
{
|
||||
pep->status = 0x0001U;
|
||||
}
|
||||
else
|
||||
{
|
||||
pep->status = 0x0000U;
|
||||
}
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pep->status, 2U);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetDescriptor
|
||||
* Handle Get Descriptor requests
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetDescriptor(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint16_t len = 0U;
|
||||
uint8_t *pbuf = NULL;
|
||||
uint8_t err = 0U;
|
||||
|
||||
switch (req->wValue >> 8)
|
||||
{
|
||||
#if (USBD_LPM_ENABLED == 1U)
|
||||
case USB_DESC_TYPE_BOS:
|
||||
if (pdev->pDesc->GetBOSDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetBOSDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case USB_DESC_TYPE_DEVICE:
|
||||
pbuf = pdev->pDesc->GetDeviceDescriptor(pdev->dev_speed, &len);
|
||||
break;
|
||||
|
||||
case USB_DESC_TYPE_CONFIGURATION:
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pbuf = pdev->pClass->GetHSConfigDescriptor(&len);
|
||||
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf = pdev->pClass->GetFSConfigDescriptor(&len);
|
||||
pbuf[1] = USB_DESC_TYPE_CONFIGURATION;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_DESC_TYPE_STRING:
|
||||
switch ((uint8_t)(req->wValue))
|
||||
{
|
||||
case USBD_IDX_LANGID_STR:
|
||||
if (pdev->pDesc->GetLangIDStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetLangIDStrDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_IDX_MFC_STR:
|
||||
if (pdev->pDesc->GetManufacturerStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetManufacturerStrDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_IDX_PRODUCT_STR:
|
||||
if (pdev->pDesc->GetProductStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetProductStrDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_IDX_SERIAL_STR:
|
||||
if (pdev->pDesc->GetSerialStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetSerialStrDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_IDX_CONFIG_STR:
|
||||
if (pdev->pDesc->GetConfigurationStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetConfigurationStrDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_IDX_INTERFACE_STR:
|
||||
if (pdev->pDesc->GetInterfaceStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pDesc->GetInterfaceStrDescriptor(pdev->dev_speed, &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
#if (USBD_SUPPORT_USER_STRING_DESC == 1U)
|
||||
if (pdev->pClass->GetUsrStrDescriptor != NULL)
|
||||
{
|
||||
pbuf = pdev->pClass->GetUsrStrDescriptor(pdev, (req->wValue), &len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
#else
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_DESC_TYPE_DEVICE_QUALIFIER:
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pbuf = pdev->pClass->GetDeviceQualifierDescriptor(&len);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION:
|
||||
if (pdev->dev_speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
pbuf = pdev->pClass->GetOtherSpeedConfigDescriptor(&len);
|
||||
pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION;
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
err++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (err != 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((len != 0U) && (req->wLength != 0U))
|
||||
{
|
||||
len = MIN(len, req->wLength);
|
||||
(void)USBD_CtlSendData(pdev, pbuf, len);
|
||||
}
|
||||
|
||||
if (req->wLength == 0U)
|
||||
{
|
||||
(void)USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetAddress
|
||||
* Set device address
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetAddress(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
uint8_t dev_addr;
|
||||
|
||||
if ((req->wIndex == 0U) && (req->wLength == 0U) && (req->wValue < 128U))
|
||||
{
|
||||
dev_addr = (uint8_t)(req->wValue) & 0x7FU;
|
||||
|
||||
if (pdev->dev_state == USBD_STATE_CONFIGURED)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->dev_address = dev_addr;
|
||||
USBD_LL_SetUSBAddress(pdev, dev_addr);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
|
||||
if (dev_addr != 0U)
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
}
|
||||
else
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_DEFAULT;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_SetConfig
|
||||
* Handle Set device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
static uint8_t cfgidx;
|
||||
|
||||
cfgidx = (uint8_t)(req->wValue);
|
||||
|
||||
if (cfgidx > USBD_MAX_NUM_CONFIGURATION)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_ADDRESSED:
|
||||
if (cfgidx)
|
||||
{
|
||||
pdev->dev_config = cfgidx;
|
||||
pdev->dev_state = USBD_STATE_CONFIGURED;
|
||||
if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
return;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (cfgidx == 0U)
|
||||
{
|
||||
pdev->dev_state = USBD_STATE_ADDRESSED;
|
||||
pdev->dev_config = cfgidx;
|
||||
USBD_ClrClassConfig(pdev, cfgidx);
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else if (cfgidx != pdev->dev_config)
|
||||
{
|
||||
/* Clear old configuration */
|
||||
USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
|
||||
|
||||
/* set new configuration */
|
||||
pdev->dev_config = cfgidx;
|
||||
if (USBD_SetClassConfig(pdev, cfgidx) == USBD_FAIL)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
return;
|
||||
}
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
USBD_ClrClassConfig(pdev, cfgidx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetConfig
|
||||
* Handle Get device configuration request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
if (req->wLength != 1U)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_DEFAULT:
|
||||
case USBD_STATE_ADDRESSED:
|
||||
pdev->dev_default_config = 0U;
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_default_config, 1U);
|
||||
break;
|
||||
|
||||
case USBD_STATE_CONFIGURED:
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config, 1U);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetStatus
|
||||
* Handle Get Status request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_GetStatus(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_DEFAULT:
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wLength != 0x2U)
|
||||
{
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
|
||||
#if (USBD_SELF_POWERED == 1U)
|
||||
pdev->dev_config_status = USB_CONFIG_SELF_POWERED;
|
||||
#else
|
||||
pdev->dev_config_status = 0U;
|
||||
#endif
|
||||
|
||||
if (pdev->dev_remote_wakeup)
|
||||
{
|
||||
pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP;
|
||||
}
|
||||
|
||||
USBD_CtlSendData(pdev, (uint8_t *)(void *)&pdev->dev_config_status, 2U);
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_SetFeature
|
||||
* Handle Set device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_SetFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 1U;
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_ClrFeature
|
||||
* Handle clear device feature request
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval status
|
||||
*/
|
||||
static void USBD_ClrFeature(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
switch (pdev->dev_state)
|
||||
{
|
||||
case USBD_STATE_DEFAULT:
|
||||
case USBD_STATE_ADDRESSED:
|
||||
case USBD_STATE_CONFIGURED:
|
||||
if (req->wValue == USB_FEATURE_REMOTE_WAKEUP)
|
||||
{
|
||||
pdev->dev_remote_wakeup = 0U;
|
||||
USBD_CtlSendStatus(pdev);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
USBD_CtlError(pdev, req);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_ParseSetupRequest
|
||||
* Copy buffer into setup structure
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USBD_ParseSetupRequest(USBD_SetupReqTypedef *req, uint8_t *pdata)
|
||||
{
|
||||
req->bmRequest = *(uint8_t *)(pdata);
|
||||
req->bRequest = *(uint8_t *)(pdata + 1U);
|
||||
req->wValue = SWAPBYTE(pdata + 2U);
|
||||
req->wIndex = SWAPBYTE(pdata + 4U);
|
||||
req->wLength = SWAPBYTE(pdata + 6U);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlError
|
||||
* Handle USB low level Error
|
||||
* @param pdev: device instance
|
||||
* @param req: usb request
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void USBD_CtlError(USBD_HandleTypeDef *pdev,
|
||||
USBD_SetupReqTypedef *req)
|
||||
{
|
||||
USBD_LL_StallEP(pdev, 0x80U);
|
||||
USBD_LL_StallEP(pdev, 0U);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief USBD_GetString
|
||||
* Convert Ascii string into unicode one
|
||||
* @param desc : descriptor buffer
|
||||
* @param unicode : Formatted string buffer (unicode)
|
||||
* @param len : descriptor length
|
||||
* @retval None
|
||||
*/
|
||||
void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len)
|
||||
{
|
||||
uint8_t idx = 0U;
|
||||
|
||||
if (desc != NULL)
|
||||
{
|
||||
*len = (uint16_t)USBD_GetLen(desc) * 2U + 2U;
|
||||
unicode[idx++] = *(uint8_t *)(void *)len;
|
||||
unicode[idx++] = USB_DESC_TYPE_STRING;
|
||||
|
||||
while (*desc != '\0')
|
||||
{
|
||||
unicode[idx++] = *desc++;
|
||||
unicode[idx++] = 0U;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetLen
|
||||
* return the string length
|
||||
* @param buf : pointer to the ascii string buffer
|
||||
* @retval string length
|
||||
*/
|
||||
static uint8_t USBD_GetLen(uint8_t *buf)
|
||||
{
|
||||
uint8_t len = 0U;
|
||||
|
||||
while (*buf != '\0')
|
||||
{
|
||||
len++;
|
||||
buf++;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
@ -0,0 +1,277 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_desc_template.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the USBD descriptors and string formatting method.
|
||||
* This template should be copied to the user folder,
|
||||
* renamed and customized following user needs.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_core.h"
|
||||
#include "usbd_desc.h"
|
||||
#include "usbd_conf.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
#define USBD_VID 0x0483
|
||||
#define USBD_PID 0xaaaa /* Replace '0xaaaa' with your device product ID */
|
||||
#define USBD_LANGID_STRING 0xbbb /* Replace '0xbbb' with your device language ID */
|
||||
#define USBD_MANUFACTURER_STRING "xxxxx" /* Add your manufacturer string */
|
||||
#define USBD_PRODUCT_HS_STRING "xxxxx" /* Add your product High Speed string */
|
||||
#define USBD_PRODUCT_FS_STRING "xxxxx" /* Add your product Full Speed string */
|
||||
#define USBD_CONFIGURATION_HS_STRING "xxxxx" /* Add your configuration High Speed string */
|
||||
#define USBD_INTERFACE_HS_STRING "xxxxx" /* Add your Interface High Speed string */
|
||||
#define USBD_CONFIGURATION_FS_STRING "xxxxx" /* Add your configuration Full Speed string */
|
||||
#define USBD_INTERFACE_FS_STRING "xxxxx" /* Add your Interface Full Speed string */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length);
|
||||
#ifdef USBD_SUPPORT_USER_STRING_DESC
|
||||
uint8_t *USBD_Class_USRStringDesc(USBD_SpeedTypeDef speed, uint8_t idx, uint16_t *length);
|
||||
#endif /* USBD_SUPPORT_USER_STRING_DESC */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
USBD_DescriptorsTypeDef Class_Desc =
|
||||
{
|
||||
USBD_Class_DeviceDescriptor,
|
||||
USBD_Class_LangIDStrDescriptor,
|
||||
USBD_Class_ManufacturerStrDescriptor,
|
||||
USBD_Class_ProductStrDescriptor,
|
||||
USBD_Class_SerialStrDescriptor,
|
||||
USBD_Class_ConfigStrDescriptor,
|
||||
USBD_Class_InterfaceStrDescriptor,
|
||||
};
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_DeviceDesc[USB_LEN_DEV_DESC] __ALIGN_END =
|
||||
{
|
||||
0x12, /* bLength */
|
||||
USB_DESC_TYPE_DEVICE, /* bDescriptorType */
|
||||
0x00, /* bcdUSB */
|
||||
0x02,
|
||||
0x00, /* bDeviceClass */
|
||||
0x00, /* bDeviceSubClass */
|
||||
0x00, /* bDeviceProtocol */
|
||||
USB_MAX_EP0_SIZE, /* bMaxPacketSize */
|
||||
LOBYTE(USBD_VID), /* idVendor */
|
||||
HIBYTE(USBD_VID), /* idVendor */
|
||||
LOBYTE(USBD_PID), /* idVendor */
|
||||
HIBYTE(USBD_PID), /* idVendor */
|
||||
0x00, /* bcdDevice rel. 2.00 */
|
||||
0x02,
|
||||
USBD_IDX_MFC_STR, /* Index of manufacturer string */
|
||||
USBD_IDX_PRODUCT_STR, /* Index of product string */
|
||||
USBD_IDX_SERIAL_STR, /* Index of serial number string */
|
||||
USBD_MAX_NUM_CONFIGURATION /* bNumConfigurations */
|
||||
}; /* USB_DeviceDescriptor */
|
||||
|
||||
/* USB Standard Device Descriptor */
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_LangIDDesc[USB_LEN_LANGID_STR_DESC] __ALIGN_END =
|
||||
{
|
||||
USB_LEN_LANGID_STR_DESC,
|
||||
USB_DESC_TYPE_STRING,
|
||||
LOBYTE(USBD_LANGID_STRING),
|
||||
HIBYTE(USBD_LANGID_STRING),
|
||||
};
|
||||
|
||||
uint8_t USBD_StringSerial[USB_SIZ_STRING_SERIAL] =
|
||||
{
|
||||
USB_SIZ_STRING_SERIAL,
|
||||
USB_DESC_TYPE_STRING,
|
||||
};
|
||||
|
||||
#if defined ( __ICCARM__ ) /*!< IAR Compiler */
|
||||
#pragma data_alignment=4
|
||||
#endif
|
||||
__ALIGN_BEGIN uint8_t USBD_StrDesc[USBD_MAX_STR_DESC_SIZ] __ALIGN_END;
|
||||
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len);
|
||||
static void Get_SerialNum(void);
|
||||
|
||||
/**
|
||||
* @brief Returns the device descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_DeviceDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_DeviceDesc);
|
||||
return (uint8_t *)USBD_DeviceDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the LangID string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_LangIDStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
*length = sizeof(USBD_LangIDDesc);
|
||||
return (uint8_t *)USBD_LangIDDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the product string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_ProductStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if (speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_HS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_PRODUCT_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the manufacturer string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_ManufacturerStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_MANUFACTURER_STRING, USBD_StrDesc, length);
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the serial number string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_SerialStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
*length = USB_SIZ_STRING_SERIAL;
|
||||
|
||||
/* Update the serial number string descriptor with the data from the unique ID*/
|
||||
Get_SerialNum();
|
||||
|
||||
return (uint8_t *)USBD_StringSerial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the configuration string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_ConfigStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if (speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_HS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_CONFIGURATION_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the interface string descriptor.
|
||||
* @param speed: Current device speed
|
||||
* @param length: Pointer to data length variable
|
||||
* @retval Pointer to descriptor buffer
|
||||
*/
|
||||
uint8_t *USBD_Class_InterfaceStrDescriptor(USBD_SpeedTypeDef speed, uint16_t *length)
|
||||
{
|
||||
if (speed == USBD_SPEED_HIGH)
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_INTERFACE_HS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
else
|
||||
{
|
||||
USBD_GetString((uint8_t *)USBD_INTERFACE_FS_STRING, USBD_StrDesc, length);
|
||||
}
|
||||
return USBD_StrDesc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create the serial number string descriptor
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void Get_SerialNum(void)
|
||||
{
|
||||
uint32_t deviceserial0, deviceserial1, deviceserial2;
|
||||
|
||||
deviceserial0 = *(uint32_t *)DEVICE_ID1;
|
||||
deviceserial1 = *(uint32_t *)DEVICE_ID2;
|
||||
deviceserial2 = *(uint32_t *)DEVICE_ID3;
|
||||
|
||||
deviceserial0 += deviceserial2;
|
||||
|
||||
if (deviceserial0 != 0U)
|
||||
{
|
||||
IntToUnicode(deviceserial0, &USBD_StringSerial[2], 8U);
|
||||
IntToUnicode(deviceserial1, &USBD_StringSerial[18], 4U);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert Hex 32Bits value into char
|
||||
* @param value: value to convert
|
||||
* @param pbuf: pointer to the buffer
|
||||
* @param len: buffer length
|
||||
* @retval None
|
||||
*/
|
||||
static void IntToUnicode(uint32_t value, uint8_t *pbuf, uint8_t len)
|
||||
{
|
||||
uint8_t idx = 0U;
|
||||
|
||||
for (idx = 0U ; idx < len ; idx ++)
|
||||
{
|
||||
if (((value >> 28)) < 0xAU)
|
||||
{
|
||||
pbuf[ 2U * idx] = (value >> 28) + '0';
|
||||
}
|
||||
else
|
||||
{
|
||||
pbuf[2U * idx] = (value >> 28) + 'A' - 10U;
|
||||
}
|
||||
|
||||
value = value << 4;
|
||||
|
||||
pbuf[2U * idx + 1] = 0U;
|
||||
}
|
||||
}
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
216
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
Normal file
216
Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ioreq.c
Normal file
@ -0,0 +1,216 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file usbd_ioreq.c
|
||||
* @author MCD Application Team
|
||||
* @brief This file provides the IO requests APIs for control endpoints.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© Copyright (c) 2015 STMicroelectronics.
|
||||
* All rights reserved.</center></h2>
|
||||
*
|
||||
* This software component is licensed by ST under Ultimate Liberty license
|
||||
* SLA0044, the "License"; You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at:
|
||||
* www.st.com/SLA0044
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "usbd_ioreq.h"
|
||||
|
||||
/** @addtogroup STM32_USB_DEVICE_LIBRARY
|
||||
* @{
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ
|
||||
* @brief control I/O requests module
|
||||
* @{
|
||||
*/
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_TypesDefinitions
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Defines
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Macros
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Variables
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_FunctionPrototypes
|
||||
* @{
|
||||
*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/** @defgroup USBD_IOREQ_Private_Functions
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlSendData
|
||||
* send data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_IN;
|
||||
pdev->ep_in[0].total_length = len;
|
||||
pdev->ep_in[0].rem_length = len;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueSendData
|
||||
* continue sending data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be sent
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueSendData(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
{
|
||||
/* Start the next transfer */
|
||||
USBD_LL_Transmit(pdev, 0x00U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlPrepareRx
|
||||
* receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlPrepareRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_DATA_OUT;
|
||||
pdev->ep_out[0].total_length = len;
|
||||
pdev->ep_out[0].rem_length = len;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlContinueRx
|
||||
* continue receive data on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @param buff: pointer to data buffer
|
||||
* @param len: length of data to be received
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlContinueRx(USBD_HandleTypeDef *pdev,
|
||||
uint8_t *pbuf, uint16_t len)
|
||||
{
|
||||
USBD_LL_PrepareReceive(pdev, 0U, pbuf, len);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlSendStatus
|
||||
* send zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlSendStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_IN;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_Transmit(pdev, 0x00U, NULL, 0U);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_CtlReceiveStatus
|
||||
* receive zero lzngth packet on the ctl pipe
|
||||
* @param pdev: device instance
|
||||
* @retval status
|
||||
*/
|
||||
USBD_StatusTypeDef USBD_CtlReceiveStatus(USBD_HandleTypeDef *pdev)
|
||||
{
|
||||
/* Set EP0 State */
|
||||
pdev->ep0_state = USBD_EP0_STATUS_OUT;
|
||||
|
||||
/* Start the transfer */
|
||||
USBD_LL_PrepareReceive(pdev, 0U, NULL, 0U);
|
||||
|
||||
return USBD_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief USBD_GetRxCount
|
||||
* returns the received data length
|
||||
* @param pdev: device instance
|
||||
* @param ep_addr: endpoint address
|
||||
* @retval Rx Data blength
|
||||
*/
|
||||
uint32_t USBD_GetRxCount(USBD_HandleTypeDef *pdev, uint8_t ep_addr)
|
||||
{
|
||||
return USBD_LL_GetRxDataSize(pdev, ep_addr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
||||
86
Middlewares/u8g2Lib/inc/MUIU8g2.h
Normal file
86
Middlewares/u8g2Lib/inc/MUIU8g2.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
|
||||
MUIU8g2.h
|
||||
|
||||
C++ Arduino wrapper for clib/mui.h (monochome minimal user interface)
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#ifndef MUIU8G2_HH
|
||||
#define MUIU8G2_HH
|
||||
|
||||
#include "mui.h"
|
||||
#include "mui_u8g2.h"
|
||||
|
||||
class MUIU8G2
|
||||
{
|
||||
protected:
|
||||
mui_t mui;
|
||||
public:
|
||||
MUIU8G2(void) { }
|
||||
|
||||
MUIU8G2(U8G2 &u8g2, fds_t *fds, muif_t *muif_list, size_t muif_cnt) {
|
||||
mui_Init(&mui, (void *)u8g2.getU8g2(), fds, muif_list, muif_cnt);
|
||||
}
|
||||
void begin(U8G2 &u8g2, fds_t *fds, muif_t *muif_list, size_t muif_cnt) {
|
||||
mui_Init(&mui, (void *)u8g2.getU8g2(), fds, muif_list, muif_cnt);
|
||||
}
|
||||
mui_t *getMUI(void) { return &mui; }
|
||||
|
||||
uint8_t getCurrentCursorFocusPosition(void) { return mui_GetCurrentCursorFocusPosition(&mui); }
|
||||
|
||||
int getCurrentFormId(void) { return mui_GetCurrentFormId(&mui); }
|
||||
|
||||
|
||||
void draw(void) { mui_Draw(&mui); }
|
||||
//void getSelectableFieldTextOption(fds_t *fds, uint8_t nth_token)
|
||||
// { mui_GetSelectableFieldTextOption(&mui, fds, nth_token); }
|
||||
void enterForm(fds_t *fds, uint8_t initial_cursor_position) { mui_EnterForm(&mui, fds, initial_cursor_position); }
|
||||
void leaveForm(void) { mui_LeaveForm(&mui); }
|
||||
uint8_t gotoForm(uint8_t form_id, uint8_t initial_cursor_position) { return mui_GotoForm(&mui, form_id, initial_cursor_position); }
|
||||
|
||||
void saveForm(void) { mui_SaveForm(&mui); }
|
||||
void restoreForm(void) { mui_RestoreForm(&mui); }
|
||||
void nextField(void) { mui_NextField(&mui); }
|
||||
void prevField(void) { mui_PrevField(&mui); }
|
||||
void sendSelect(void) { mui_SendSelect(&mui); }
|
||||
|
||||
void sendSelectWithExecuteOnSelectFieldSearch(void) { mui_SendSelectWithExecuteOnSelectFieldSearch(&mui); }
|
||||
|
||||
|
||||
int isFormActive(void) { return mui_IsFormActive(&mui); }
|
||||
};
|
||||
|
||||
|
||||
#endif /* MUIU8G2_HH */
|
||||
24666
Middlewares/u8g2Lib/inc/U8g2lib.h
Normal file
24666
Middlewares/u8g2Lib/inc/U8g2lib.h
Normal file
File diff suppressed because it is too large
Load Diff
8498
Middlewares/u8g2Lib/inc/U8x8lib.h
Normal file
8498
Middlewares/u8g2Lib/inc/U8x8lib.h
Normal file
File diff suppressed because it is too large
Load Diff
609
Middlewares/u8g2Lib/inc/mui.h
Normal file
609
Middlewares/u8g2Lib/inc/mui.h
Normal file
@ -0,0 +1,609 @@
|
||||
/*
|
||||
|
||||
mui.h
|
||||
|
||||
Monochrome minimal user interface: Core library.
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2021, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
MUIF (Monochrome User Interface Functions)
|
||||
n: A number 0 to 9 without any quotes, e.g.: 5
|
||||
id: Exactly two characters or numbers in double quotes, e.g. "G5".
|
||||
cb: A callback function with the following prototype: "uint8_t muif_cb(mui_t *ui, uint8_t msg)"
|
||||
There are MANY predefined callback functions, see separate list
|
||||
var: Address of a variable.
|
||||
text: Normal text, but special characters might be required for some callback functions, for
|
||||
example the text might contain a list of selectable elements separated with the '|' symbol.
|
||||
|
||||
MUIF_STYLE(n,cb)
|
||||
Corresponding FDS command: MUI_STYLE(n)
|
||||
Change the style of any other elements after MUI_STYLE(n), does not draw anything
|
||||
|
||||
MUIF_RO(id,cb)
|
||||
Corresponding FDS command: MUI_DATA(id, text) MUI_XY(id, x, y), MUI_XYT(id, x,y,text), MUI_XYA(id, x,y,a), MUI_XYAT(id, x,y,a,text)
|
||||
Places a read only element on the form.
|
||||
The correct FDS command depends on the callback function.
|
||||
|
||||
MUIF_LABEL(cb)
|
||||
Corresponding FDS command: MUI_LABEL(x,y,text)
|
||||
Places a text at the specified position, similar to MUIF_RO
|
||||
|
||||
MUIF_GOTO(cb)
|
||||
Corresponding FDS command: MUI_GOTO(x,y,n,text)
|
||||
Places a button at the specified position, similar to MUIF_BUTTON, but does not require an ID.
|
||||
|
||||
MUIF_BUTTON(id,cb)
|
||||
Corresponding FDS command: MUI_XY(id, x, y), MUI_XYT(id, x,y,text), MUI_XYA(id, x,y,a), MUI_XYAT(id, x,y,a,text)
|
||||
Places a selectable element on the form.
|
||||
|
||||
MUIF_VARIABLE(id,var,cb)
|
||||
Corresponding FDS command: MUI_XY(id, x, y), MUI_XYA(id, x,y,a)
|
||||
Places a user input element at the specified location.
|
||||
The correct FDS command depends on the callback function.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MUI_H
|
||||
#define MUI_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(__GNUC__) && defined(__AVR__)
|
||||
#include <avr/pgmspace.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
/* C++ compatible */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*==========================================*/
|
||||
/* defines */
|
||||
|
||||
#define MUI_CHECK_EOFDS
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
/* GNUC AVR PROGMEM interface */
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define MUI_NOINLINE __attribute__((noinline))
|
||||
#else
|
||||
# define MUI_NOINLINE
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__GNUC__) && defined(__AVR__)
|
||||
# define mui_pgm_read(adr) pgm_read_byte_near(adr)
|
||||
# define mui_pgm_wread(adr) pgm_read_word_near(adr)
|
||||
# define MUI_PROGMEM PROGMEM
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef mui_pgm_read
|
||||
# ifndef CHAR_BIT
|
||||
# define mui_pgm_read(adr) (*(const uint8_t *)(adr))
|
||||
# else
|
||||
# if CHAR_BIT > 8
|
||||
# define mui_pgm_read(adr) ((*(const uint8_t *)(adr)) & 0x0ff)
|
||||
# else
|
||||
# define mui_pgm_read(adr) (*(const uint8_t *)(adr))
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef mui_pgm_wread
|
||||
# define mui_pgm_wread(adr) (*(const uint16_t *)(adr))
|
||||
#endif
|
||||
|
||||
#ifndef MUI_PROGMEM
|
||||
# define MUI_PROGMEM
|
||||
#endif
|
||||
|
||||
|
||||
/*=== forward declarations ===*/
|
||||
typedef struct mui_struct mui_t;
|
||||
typedef const struct muif_struct muif_t;
|
||||
typedef uint8_t (*muif_cb)(mui_t *ui, uint8_t msg);
|
||||
typedef const char fds_t MUI_PROGMEM;
|
||||
|
||||
|
||||
|
||||
/*=== struct declarations === */
|
||||
|
||||
struct muif_struct
|
||||
{
|
||||
uint8_t id0;
|
||||
uint8_t id1;
|
||||
uint8_t cflags; // config flags e.g. MUIF_CFLAG_IS_CURSOR_SELECTABLE, if so, then it will not receive any cursor/touch msgs
|
||||
uint8_t extra;
|
||||
void *data; // might be a pointer to a variable
|
||||
muif_cb cb; // callback
|
||||
} MUI_PROGMEM;
|
||||
|
||||
/* assumes that pointers are 16 bit so encapsulate the wread i another ifdef __AVR__ */
|
||||
#if defined(__GNUC__) && defined(__AVR__)
|
||||
# define muif_get_id0(muif) mui_pgm_read(&((muif)->id0))
|
||||
# define muif_get_id1(muif) mui_pgm_read(&((muif)->id1))
|
||||
# define muif_get_cflags(muif) mui_pgm_read(&((muif)->cflags))
|
||||
# define muif_get_extra(muif) mui_pgm_read(&((muif)->extra))
|
||||
# define muif_get_data(muif) ((void *)mui_pgm_wread(&((muif)->data)))
|
||||
# define muif_get_cb(muif) ((muif_cb)mui_pgm_wread(&((muif)->cb)))
|
||||
#else
|
||||
# define muif_get_id0(muif) ((muif)->id0)
|
||||
# define muif_get_id1(muif) ((muif)->id1)
|
||||
# define muif_get_cflags(muif) ((muif)->cflags)
|
||||
# define muif_get_extra(muif) ((muif)->extra)
|
||||
# define muif_get_data(muif) ((muif)->data)
|
||||
# define muif_get_cb(muif) ((muif)->cb)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define MUIF_MSG_NONE 0
|
||||
#define MUIF_MSG_DRAW 1
|
||||
#define MUIF_MSG_FORM_START 2
|
||||
#define MUIF_MSG_FORM_END 3
|
||||
/* MUIF_MSG_CURSOR_ENTER return values: 255=skip this field, <255, continue*/
|
||||
#define MUIF_MSG_CURSOR_ENTER 4
|
||||
#define MUIF_MSG_CURSOR_SELECT 5
|
||||
|
||||
/* optional VALUE messages, ignored by the mui core, but can be used inside the field functions */
|
||||
/* usually MUIF_MSG_VALUE_INCREMENT behaves like MUIF_MSG_CURSOR_SELECT */
|
||||
#define MUIF_MSG_VALUE_INCREMENT 6
|
||||
#define MUIF_MSG_VALUE_DECREMENT 7
|
||||
|
||||
|
||||
#define MUIF_MSG_CURSOR_LEAVE 8
|
||||
#define MUIF_MSG_TOUCH_DOWN 9
|
||||
#define MUIF_MSG_TOUCH_UP 10
|
||||
/* MUIF_MSG_EVENT_NEXT return values: 0=not handled, 1=handled, do nothing */
|
||||
/* If MUIF_MSG_EVENT_NEXT/PREV are NOT handled by the field function, then this msg will change the field */
|
||||
#define MUIF_MSG_EVENT_NEXT 11
|
||||
/* MUIF_MSG_EVENT_PREV return values: 0=not handled, 1=handled, do nothing */
|
||||
#define MUIF_MSG_EVENT_PREV 12
|
||||
|
||||
/* dynamic flags */
|
||||
#define MUIF_DFLAG_IS_CURSOR_FOCUS 0x01
|
||||
#define MUIF_DFLAG_IS_TOUCH_FOCUS 0x02
|
||||
|
||||
/* config flags */
|
||||
#define MUIF_CFLAG_IS_CURSOR_SELECTABLE 0x01
|
||||
#define MUIF_CFLAG_IS_TOUCH_SELECTABLE 0x02
|
||||
#define MUIF_CFLAG_IS_EXECUTE_ON_SELECT 0x04
|
||||
|
||||
|
||||
/* end user MUIF entries */
|
||||
#define MUIF(id,cflags,data,cb) { id[0], id[1], cflags, 0, data, cb}
|
||||
#define MUIF_STYLE(n,cb) MUIF("S" #n, 0, 0, cb)
|
||||
#define MUIF_RO(id,cb) MUIF(id,0, 0,cb)
|
||||
#define MUIF_LABEL(cb) MUIF(".L",0, 0,cb)
|
||||
#define MUIF_GOTO(cb) MUIF(".G",MUIF_CFLAG_IS_CURSOR_SELECTABLE,0,cb)
|
||||
#define MUIF_BUTTON(id,cb) MUIF(id,MUIF_CFLAG_IS_CURSOR_SELECTABLE,0,cb)
|
||||
#define MUIF_EXECUTE_ON_SELECT_BUTTON(id,cb) MUIF(id,MUIF_CFLAG_IS_CURSOR_SELECTABLE|MUIF_CFLAG_IS_EXECUTE_ON_SELECT,0,cb)
|
||||
#define MUIF_VARIABLE(id,var,cb) MUIF(id,MUIF_CFLAG_IS_CURSOR_SELECTABLE,(var),cb)
|
||||
|
||||
|
||||
|
||||
/* must be smaller than or equal to 255 */
|
||||
#ifndef MUI_MAX_TEXT_LEN
|
||||
#define MUI_MAX_TEXT_LEN 41
|
||||
#endif
|
||||
|
||||
#define MUI_MENU_CACHE_CNT 2
|
||||
|
||||
struct mui_struct
|
||||
{
|
||||
void *graphics_data;
|
||||
fds_t *root_fds;
|
||||
|
||||
muif_t *muif_tlist;
|
||||
size_t muif_tcnt;
|
||||
|
||||
fds_t *current_form_fds; // the current form, NULL if the ui is not active at the moment
|
||||
fds_t *cursor_focus_fds; // the field which has the current cursor focus, NULL if there is no current focus
|
||||
fds_t *touch_focus_fds; // the field which has touch focus
|
||||
|
||||
fds_t *token; // current token position
|
||||
|
||||
uint16_t form_scroll_total; // reserved for MUIF, not used by mui
|
||||
uint16_t form_scroll_top; // reserved for MUIF, not used by mui
|
||||
uint8_t form_scroll_visible; // reserved for MUIF, not used by mui
|
||||
|
||||
|
||||
//uint8_t selected_value; // This variable is not used by the user interface but can be used by any field function
|
||||
uint8_t tmp8;
|
||||
|
||||
/* 0: mse, 1: mud */
|
||||
uint8_t is_mud; // a temp variable for the MUIF function to store remember up down mode. This variable will be cleared before sending MUIF_MSG_CURSOR_ENTER
|
||||
/* current field/style variables */
|
||||
//uint8_t cursor_focus_position; // the index of the field which has focus, can be used as last argument for mui_EnterForm
|
||||
|
||||
uint8_t delimiter; // outer delimiter of the text part of a field
|
||||
uint8_t cmd; // current cmd or field (e.g. U or F)
|
||||
uint8_t id0; // identifier of the field, manually provided or derived (G cmd has fixed id "FG")
|
||||
uint8_t id1;
|
||||
uint8_t x; // position of the field
|
||||
uint8_t y;
|
||||
uint8_t dflags;
|
||||
uint8_t arg; // extra argument of the field. For example the G: form is put here
|
||||
int len; // length of the current command
|
||||
fds_t *fds; // current position, *fds = cmd
|
||||
muif_t *uif; // user interface field or style for the given id0 / id1, assigned by mui_prepare_current_field()
|
||||
char text[MUI_MAX_TEXT_LEN+1];
|
||||
|
||||
/* target */
|
||||
fds_t *tmp_fds;
|
||||
fds_t *target_fds; // used by several task functions as a return / result value
|
||||
|
||||
/* last form and field, used by mui_SaveForm and mui_RestoreForm */
|
||||
uint8_t last_form_id;
|
||||
uint8_t last_form_cursor_focus_position;
|
||||
fds_t *last_form_fds; // not used by mui_RestoreForm, but can be used by field functions
|
||||
|
||||
/* menu cursor position backup */
|
||||
uint8_t menu_form_id[MUI_MENU_CACHE_CNT];
|
||||
uint8_t menu_form_cursor_focus_position[MUI_MENU_CACHE_CNT];
|
||||
uint8_t menu_form_last_added;
|
||||
} ;
|
||||
|
||||
#define mui_IsCursorFocus(mui) ((mui)->dflags & MUIF_DFLAG_IS_CURSOR_FOCUS)
|
||||
#define mui_IsTouchFocus(mui) ((mui)->dflags & MUIF_CFLAG_IS_TOUCH_SELECTABLE)
|
||||
|
||||
|
||||
|
||||
|
||||
/*=== form string definitions ===*/
|
||||
|
||||
#define MUI_0 "\x00"
|
||||
#define MUI_1 "\x01"
|
||||
#define MUI_2 "\x02"
|
||||
#define MUI_3 "\x03"
|
||||
#define MUI_4 "\x04"
|
||||
#define MUI_5 "\x05"
|
||||
#define MUI_6 "\x06"
|
||||
#define MUI_7 "\x07"
|
||||
#define MUI_8 "\x08"
|
||||
#define MUI_9 "\x09"
|
||||
#define MUI_10 "\x0a"
|
||||
#define MUI_11 "\x0b"
|
||||
#define MUI_12 "\x0c"
|
||||
#define MUI_13 "\x0d"
|
||||
#define MUI_14 "\x0e"
|
||||
#define MUI_15 "\x0f"
|
||||
#define MUI_16 "\x10"
|
||||
#define MUI_17 "\x11"
|
||||
#define MUI_18 "\x12"
|
||||
#define MUI_19 "\x13"
|
||||
#define MUI_20 "\x14"
|
||||
#define MUI_21 "\x15"
|
||||
#define MUI_22 "\x16"
|
||||
#define MUI_23 "\x17"
|
||||
#define MUI_24 "\x18"
|
||||
#define MUI_25 "\x19"
|
||||
#define MUI_26 "\x1a"
|
||||
#define MUI_27 "\x1b"
|
||||
#define MUI_28 "\x1c"
|
||||
#define MUI_29 "\x1d"
|
||||
#define MUI_30 "\x1e"
|
||||
#define MUI_31 "\x1f"
|
||||
#define MUI_32 "\x20"
|
||||
#define MUI_33 "\x21"
|
||||
#define MUI_34 "\x22"
|
||||
#define MUI_35 "\x23"
|
||||
#define MUI_36 "\x24"
|
||||
#define MUI_37 "\x25"
|
||||
#define MUI_38 "\x26"
|
||||
#define MUI_39 "\x27"
|
||||
#define MUI_40 "\x28"
|
||||
#define MUI_41 "\x29"
|
||||
#define MUI_42 "\x2a"
|
||||
#define MUI_43 "\x2b"
|
||||
#define MUI_44 "\x2c"
|
||||
#define MUI_45 "\x2d"
|
||||
#define MUI_46 "\x2e"
|
||||
#define MUI_47 "\x2f"
|
||||
#define MUI_48 "\x30"
|
||||
#define MUI_49 "\x31"
|
||||
#define MUI_50 "\x32"
|
||||
#define MUI_51 "\x33"
|
||||
#define MUI_52 "\x34"
|
||||
#define MUI_53 "\x35"
|
||||
#define MUI_54 "\x36"
|
||||
#define MUI_55 "\x37"
|
||||
#define MUI_56 "\x38"
|
||||
#define MUI_57 "\x39"
|
||||
#define MUI_58 "\x3a"
|
||||
#define MUI_59 "\x3b"
|
||||
#define MUI_60 "\x3c"
|
||||
#define MUI_61 "\x3d"
|
||||
#define MUI_62 "\x3e"
|
||||
#define MUI_63 "\x3f"
|
||||
#define MUI_64 "\x40"
|
||||
#define MUI_65 "\x41"
|
||||
#define MUI_66 "\x42"
|
||||
#define MUI_67 "\x43"
|
||||
#define MUI_68 "\x44"
|
||||
#define MUI_69 "\x45"
|
||||
#define MUI_70 "\x46"
|
||||
#define MUI_71 "\x47"
|
||||
#define MUI_72 "\x48"
|
||||
#define MUI_73 "\x49"
|
||||
#define MUI_74 "\x4a"
|
||||
#define MUI_75 "\x4b"
|
||||
#define MUI_76 "\x4c"
|
||||
#define MUI_77 "\x4d"
|
||||
#define MUI_78 "\x4e"
|
||||
#define MUI_79 "\x4f"
|
||||
#define MUI_80 "\x50"
|
||||
#define MUI_81 "\x51"
|
||||
#define MUI_82 "\x52"
|
||||
#define MUI_83 "\x53"
|
||||
#define MUI_84 "\x54"
|
||||
#define MUI_85 "\x55"
|
||||
#define MUI_86 "\x56"
|
||||
#define MUI_87 "\x57"
|
||||
#define MUI_88 "\x58"
|
||||
#define MUI_89 "\x59"
|
||||
#define MUI_90 "\x5a"
|
||||
#define MUI_91 "\x5b"
|
||||
#define MUI_92 "\x5c"
|
||||
#define MUI_93 "\x5d"
|
||||
#define MUI_94 "\x5e"
|
||||
#define MUI_95 "\x5f"
|
||||
#define MUI_96 "\x60"
|
||||
#define MUI_97 "\x61"
|
||||
#define MUI_98 "\x62"
|
||||
#define MUI_99 "\x63"
|
||||
#define MUI_100 "\x64"
|
||||
#define MUI_101 "\x65"
|
||||
#define MUI_102 "\x66"
|
||||
#define MUI_103 "\x67"
|
||||
#define MUI_104 "\x68"
|
||||
#define MUI_105 "\x69"
|
||||
#define MUI_106 "\x6a"
|
||||
#define MUI_107 "\x6b"
|
||||
#define MUI_108 "\x6c"
|
||||
#define MUI_109 "\x6d"
|
||||
#define MUI_110 "\x6e"
|
||||
#define MUI_111 "\x6f"
|
||||
#define MUI_112 "\x70"
|
||||
#define MUI_113 "\x71"
|
||||
#define MUI_114 "\x72"
|
||||
#define MUI_115 "\x73"
|
||||
#define MUI_116 "\x74"
|
||||
#define MUI_117 "\x75"
|
||||
#define MUI_118 "\x76"
|
||||
#define MUI_119 "\x77"
|
||||
#define MUI_120 "\x78"
|
||||
#define MUI_121 "\x79"
|
||||
#define MUI_122 "\x7a"
|
||||
#define MUI_123 "\x7b"
|
||||
#define MUI_124 "\x7c"
|
||||
#define MUI_125 "\x7d"
|
||||
#define MUI_126 "\x7e"
|
||||
#define MUI_127 "\x7f"
|
||||
#define MUI_128 "\x80"
|
||||
#define MUI_129 "\x81"
|
||||
#define MUI_130 "\x82"
|
||||
#define MUI_131 "\x83"
|
||||
#define MUI_132 "\x84"
|
||||
#define MUI_133 "\x85"
|
||||
#define MUI_134 "\x86"
|
||||
#define MUI_135 "\x87"
|
||||
#define MUI_136 "\x88"
|
||||
#define MUI_137 "\x89"
|
||||
#define MUI_138 "\x8a"
|
||||
#define MUI_139 "\x8b"
|
||||
#define MUI_140 "\x8c"
|
||||
#define MUI_141 "\x8d"
|
||||
#define MUI_142 "\x8e"
|
||||
#define MUI_143 "\x8f"
|
||||
#define MUI_144 "\x90"
|
||||
#define MUI_145 "\x91"
|
||||
#define MUI_146 "\x92"
|
||||
#define MUI_147 "\x93"
|
||||
#define MUI_148 "\x94"
|
||||
#define MUI_149 "\x95"
|
||||
#define MUI_150 "\x96"
|
||||
#define MUI_151 "\x97"
|
||||
#define MUI_152 "\x98"
|
||||
#define MUI_153 "\x99"
|
||||
#define MUI_154 "\x9a"
|
||||
#define MUI_155 "\x9b"
|
||||
#define MUI_156 "\x9c"
|
||||
#define MUI_157 "\x9d"
|
||||
#define MUI_158 "\x9e"
|
||||
#define MUI_159 "\x9f"
|
||||
#define MUI_160 "\xa0"
|
||||
#define MUI_161 "\xa1"
|
||||
#define MUI_162 "\xa2"
|
||||
#define MUI_163 "\xa3"
|
||||
#define MUI_164 "\xa4"
|
||||
#define MUI_165 "\xa5"
|
||||
#define MUI_166 "\xa6"
|
||||
#define MUI_167 "\xa7"
|
||||
#define MUI_168 "\xa8"
|
||||
#define MUI_169 "\xa9"
|
||||
#define MUI_170 "\xaa"
|
||||
#define MUI_171 "\xab"
|
||||
#define MUI_172 "\xac"
|
||||
#define MUI_173 "\xad"
|
||||
#define MUI_174 "\xae"
|
||||
#define MUI_175 "\xaf"
|
||||
#define MUI_176 "\xb0"
|
||||
#define MUI_177 "\xb1"
|
||||
#define MUI_178 "\xb2"
|
||||
#define MUI_179 "\xb3"
|
||||
#define MUI_180 "\xb4"
|
||||
#define MUI_181 "\xb5"
|
||||
#define MUI_182 "\xb6"
|
||||
#define MUI_183 "\xb7"
|
||||
#define MUI_184 "\xb8"
|
||||
#define MUI_185 "\xb9"
|
||||
#define MUI_186 "\xba"
|
||||
#define MUI_187 "\xbb"
|
||||
#define MUI_188 "\xbc"
|
||||
#define MUI_189 "\xbd"
|
||||
#define MUI_190 "\xbe"
|
||||
#define MUI_191 "\xbf"
|
||||
#define MUI_192 "\xc0"
|
||||
#define MUI_193 "\xc1"
|
||||
#define MUI_194 "\xc2"
|
||||
#define MUI_195 "\xc3"
|
||||
#define MUI_196 "\xc4"
|
||||
#define MUI_197 "\xc5"
|
||||
#define MUI_198 "\xc6"
|
||||
#define MUI_199 "\xc7"
|
||||
#define MUI_200 "\xc8"
|
||||
#define MUI_201 "\xc9"
|
||||
#define MUI_202 "\xca"
|
||||
#define MUI_203 "\xcb"
|
||||
#define MUI_204 "\xcc"
|
||||
#define MUI_205 "\xcd"
|
||||
#define MUI_206 "\xce"
|
||||
#define MUI_207 "\xcf"
|
||||
#define MUI_208 "\xd0"
|
||||
#define MUI_209 "\xd1"
|
||||
#define MUI_210 "\xd2"
|
||||
#define MUI_211 "\xd3"
|
||||
#define MUI_212 "\xd4"
|
||||
#define MUI_213 "\xd5"
|
||||
#define MUI_214 "\xd6"
|
||||
#define MUI_215 "\xd7"
|
||||
#define MUI_216 "\xd8"
|
||||
#define MUI_217 "\xd9"
|
||||
#define MUI_218 "\xda"
|
||||
#define MUI_219 "\xdb"
|
||||
#define MUI_220 "\xdc"
|
||||
#define MUI_221 "\xdd"
|
||||
#define MUI_222 "\xde"
|
||||
#define MUI_223 "\xdf"
|
||||
#define MUI_224 "\xe0"
|
||||
#define MUI_225 "\xe1"
|
||||
#define MUI_226 "\xe2"
|
||||
#define MUI_227 "\xe3"
|
||||
#define MUI_228 "\xe4"
|
||||
#define MUI_229 "\xe5"
|
||||
#define MUI_230 "\xe6"
|
||||
#define MUI_231 "\xe7"
|
||||
#define MUI_232 "\xe8"
|
||||
#define MUI_233 "\xe9"
|
||||
#define MUI_234 "\xea"
|
||||
#define MUI_235 "\xeb"
|
||||
#define MUI_236 "\xec"
|
||||
#define MUI_237 "\xed"
|
||||
#define MUI_238 "\xee"
|
||||
#define MUI_239 "\xef"
|
||||
#define MUI_240 "\xf0"
|
||||
#define MUI_241 "\xf1"
|
||||
#define MUI_242 "\xf2"
|
||||
#define MUI_243 "\xf3"
|
||||
#define MUI_244 "\xf4"
|
||||
#define MUI_245 "\xf5"
|
||||
#define MUI_246 "\xf6"
|
||||
#define MUI_247 "\xf7"
|
||||
#define MUI_248 "\xf8"
|
||||
#define MUI_249 "\xf9"
|
||||
#define MUI_250 "\xfa"
|
||||
#define MUI_251 "\xfb"
|
||||
#define MUI_252 "\xfc"
|
||||
#define MUI_253 "\xfd"
|
||||
#define MUI_254 "\xfe"
|
||||
#define MUI_255 "\xff"
|
||||
|
||||
/* form: one id only */
|
||||
#define MUI_FORM(n) "U" MUI_##n
|
||||
|
||||
/* style: one id only */
|
||||
#define MUI_STYLE(n) "S" #n
|
||||
|
||||
#define MUI_AUX(id) "Z" id
|
||||
|
||||
#define MUI_DATA(id, text) "D" id "\xff" text "\xff"
|
||||
|
||||
#define MUI_XY(id, x, y) "F" id MUI_##x MUI_##y
|
||||
/* button id must be two chars, but must be unique everywhere */
|
||||
#define MUI_XYT(id, x,y,text) "B" id MUI_##x MUI_##y "\xff" text "\xff"
|
||||
#define MUI_XYA(id, x,y,a) "A" id MUI_##x MUI_##y MUI_##a
|
||||
#define MUI_XYAT(id, x,y,a,text) "T" id MUI_##x MUI_##y MUI_##a "\xff" text "\xff"
|
||||
|
||||
#define MUI_LABEL(x,y,text) "L" MUI_##x MUI_##y "\xff" text "\xff"
|
||||
#define MUI_GOTO(x,y,n,text) "G" MUI_##x MUI_##y MUI_##n "\xff" text "\xff"
|
||||
#define MUI_goto(x,y,n,text) "g" MUI_##x MUI_##y MUI_##n "\xff" text "\xff"
|
||||
|
||||
|
||||
uint8_t mui_get_fds_char(fds_t *s) MUI_NOINLINE;
|
||||
|
||||
uint8_t mui_fds_first_token(mui_t *ui) MUI_NOINLINE;
|
||||
uint8_t mui_fds_next_token(mui_t *ui) MUI_NOINLINE;
|
||||
uint8_t mui_fds_get_nth_token(mui_t *ui, uint8_t n) MUI_NOINLINE;
|
||||
uint8_t mui_fds_get_token_cnt(mui_t *ui) MUI_NOINLINE;
|
||||
|
||||
void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, size_t muif_tcnt);
|
||||
uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui) ;
|
||||
void mui_Draw(mui_t *ui);
|
||||
/* warning: The next function will overwrite the ui field variables like ui->arg, etc. 26 sep 2021: only ui->text is modified */
|
||||
uint8_t mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, uint8_t nth_token);
|
||||
/* warning: The next function will overwrite the ui field variables like ui->arg, etc 26 sep 2021: only ui->text is modified*/
|
||||
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds);
|
||||
void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position);
|
||||
void mui_LeaveForm(mui_t *ui);
|
||||
uint8_t mui_GotoForm(mui_t *ui, uint8_t form_id, uint8_t initial_cursor_position);
|
||||
void mui_SaveForm(mui_t *ui); /* Save current form+cursor position. Used together with mui_RestoreForm */
|
||||
void mui_RestoreForm(mui_t *ui); /* Restore form and cursor position, previously saved with mui_SaveForm */
|
||||
void mui_SaveCursorPosition(mui_t *ui, uint8_t cursor_position); /* stores a cursor position for use with mui_GotoFormAutoCursorPosition */
|
||||
uint8_t mui_GotoFormAutoCursorPosition(mui_t *ui, uint8_t form_id);
|
||||
|
||||
int mui_GetCurrentFormId(mui_t *ui); /* form id or -1 if the menu system is inactive */
|
||||
void mui_NextField(mui_t *ui);
|
||||
void mui_PrevField(mui_t *ui);
|
||||
void mui_SendSelect(mui_t *ui);
|
||||
void mui_SendSelectWithExecuteOnSelectFieldSearch(mui_t *ui); /* use this if MUIF_EXECUTE_ON_SELECT_BUTTON is used */
|
||||
|
||||
void mui_SendValueIncrement(mui_t *ui);
|
||||
void mui_SendValueDecrement(mui_t *ui);
|
||||
|
||||
|
||||
|
||||
#define mui_IsFormActive(ui) ((ui)->current_form_fds != NULL)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* MUI_H */
|
||||
|
||||
258
Middlewares/u8g2Lib/inc/mui_u8g2.h
Normal file
258
Middlewares/u8g2Lib/inc/mui_u8g2.h
Normal file
@ -0,0 +1,258 @@
|
||||
/*
|
||||
|
||||
mui_u8g2.h
|
||||
|
||||
Monochrome minimal user interface: Glue code between mui and u8g2.
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2021, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef MUI_U8G2_H
|
||||
#define MUI_U8G2_H
|
||||
|
||||
#include "mui.h"
|
||||
|
||||
/*==========================================*/
|
||||
/* C++ compatible */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define MUI_U8G2_COMMA ,
|
||||
|
||||
typedef const char * (*mui_u8g2_get_list_element_cb)(void *data, uint16_t index);
|
||||
typedef uint16_t (*mui_u8g2_get_list_count_cb)(void *data);
|
||||
|
||||
struct mui_u8g2_list_struct
|
||||
{
|
||||
uint16_t *selection;
|
||||
void *data;
|
||||
mui_u8g2_get_list_element_cb get_list_element;
|
||||
mui_u8g2_get_list_count_cb get_list_count;
|
||||
} MUI_PROGMEM;
|
||||
|
||||
typedef const struct mui_u8g2_list_struct mui_u8g2_list_t;
|
||||
|
||||
#if defined(__GNUC__) && defined(__AVR__)
|
||||
# define mui_u8g2_list_get_selection_ptr(list) ((uint16_t *)mui_pgm_wread(&((list)->selection)))
|
||||
# define mui_u8g2_list_get_data_ptr(list) ((void *)mui_pgm_wread(&((list)->data)))
|
||||
# define mui_u8g2_list_get_element_cb(list) ((mui_u8g2_get_list_element_cb)mui_pgm_wread(&((list)->get_list_element)))
|
||||
# define mui_u8g2_list_get_count_cb(list) ((mui_u8g2_get_list_count_cb)mui_pgm_wread(&((list)->get_list_count)))
|
||||
#else
|
||||
# define mui_u8g2_list_get_selection_ptr(list) ((list)->selection)
|
||||
# define mui_u8g2_list_get_data_ptr(list) ((list)->data)
|
||||
# define mui_u8g2_list_get_element_cb(list) ((list)->get_list_element)
|
||||
# define mui_u8g2_list_get_count_cb(list) ((list)->get_list_count)
|
||||
#endif
|
||||
|
||||
|
||||
struct mui_u8g2_u8_min_max_struct
|
||||
{
|
||||
uint8_t *value;
|
||||
uint8_t min;
|
||||
uint8_t max;
|
||||
} MUI_PROGMEM;
|
||||
|
||||
typedef const struct mui_u8g2_u8_min_max_struct mui_u8g2_u8_min_max_t;
|
||||
|
||||
#if defined(__GNUC__) && defined(__AVR__)
|
||||
# define mui_u8g2_u8mm_get_min(u8mm) mui_pgm_read(&((u8mm)->min))
|
||||
# define mui_u8g2_u8mm_get_max(u8mm) mui_pgm_read(&((u8mm)->max))
|
||||
# define mui_u8g2_u8mm_get_valptr(u8mm) ((uint8_t *)mui_pgm_wread(&((u8mm)->value)))
|
||||
#else
|
||||
# define mui_u8g2_u8mm_get_min(u8mm) ((u8mm)->min)
|
||||
# define mui_u8g2_u8mm_get_max(u8mm) ((u8mm)->max)
|
||||
# define mui_u8g2_u8mm_get_valptr(u8mm) ((u8mm)->value)
|
||||
#endif
|
||||
|
||||
|
||||
struct mui_u8g2_u8_min_max_step_struct
|
||||
{
|
||||
uint8_t *value;
|
||||
uint8_t min;
|
||||
uint8_t max;
|
||||
uint8_t step;
|
||||
uint8_t flags;
|
||||
} MUI_PROGMEM;
|
||||
|
||||
typedef const struct mui_u8g2_u8_min_max_step_struct mui_u8g2_u8_min_max_step_t;
|
||||
|
||||
#if defined(__GNUC__) && defined(__AVR__)
|
||||
# define mui_u8g2_u8mms_get_step(u8mm) mui_pgm_read(&((u8mm)->step))
|
||||
# define mui_u8g2_u8mms_get_flags(u8mm) mui_pgm_read(&((u8mm)->flags))
|
||||
# define mui_u8g2_u8mms_get_min(u8mm) mui_pgm_read(&((u8mm)->min))
|
||||
# define mui_u8g2_u8mms_get_max(u8mm) mui_pgm_read(&((u8mm)->max))
|
||||
# define mui_u8g2_u8mms_get_valptr(u8mm) ((uint8_t *)mui_pgm_wread(&((u8mm)->value)))
|
||||
#else
|
||||
# define mui_u8g2_u8mms_get_step(u8mm) ((u8mm)->step)
|
||||
# define mui_u8g2_u8mms_get_flags(u8mm) ((u8mm)->flags)
|
||||
# define mui_u8g2_u8mms_get_min(u8mm) ((u8mm)->min)
|
||||
# define mui_u8g2_u8mms_get_max(u8mm) ((u8mm)->max)
|
||||
# define mui_u8g2_u8mms_get_valptr(u8mm) ((u8mm)->value)
|
||||
#endif
|
||||
|
||||
|
||||
/* helper functions */
|
||||
|
||||
u8g2_uint_t mui_get_x(mui_t *ui);
|
||||
u8g2_uint_t mui_get_y(mui_t *ui);
|
||||
u8g2_t *mui_get_U8g2(mui_t *ui);
|
||||
|
||||
void mui_u8g2_draw_button_utf(mui_t *ui, u8g2_uint_t flags, u8g2_uint_t width, u8g2_uint_t padding_h, u8g2_uint_t padding_v, const char *text);
|
||||
u8g2_uint_t mui_u8g2_get_pi_flags(mui_t *ui);
|
||||
void mui_u8g2_draw_button_pi(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text);
|
||||
u8g2_uint_t mui_u8g2_get_fi_flags(mui_t *ui);
|
||||
void mui_u8g2_draw_button_fi(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text);
|
||||
u8g2_uint_t mui_u8g2_get_pf_flags(mui_t *ui);
|
||||
void mui_u8g2_draw_button_pf(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text);
|
||||
u8g2_uint_t mui_u8g2_get_if_flags(mui_t *ui);
|
||||
void mui_u8g2_draw_button_if(mui_t *ui, u8g2_uint_t width, u8g2_uint_t padding_h, const char *text);
|
||||
|
||||
|
||||
|
||||
/* ready to use field functions */
|
||||
|
||||
uint8_t mui_u8g2_draw_text(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_btn_goto_wm_fi(mui_t *ui, uint8_t msg); /* GIF */
|
||||
uint8_t mui_u8g2_btn_goto_wm_if(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_btn_goto_w2_fi(mui_t *ui, uint8_t msg); /* GIF */
|
||||
uint8_t mui_u8g2_btn_goto_w2_if(mui_t *ui, uint8_t msg);
|
||||
|
||||
uint8_t mui_u8g2_btn_goto_w1_pi(mui_t *ui, uint8_t msg); /* GIF */
|
||||
uint8_t mui_u8g2_btn_goto_w1_fi(mui_t *ui, uint8_t msg); /* GIF */
|
||||
|
||||
uint8_t mui_u8g2_btn_exit_wm_fi(mui_t *ui, uint8_t msg); /* similar to 'mui_u8g2_btn_goto_wm_fi' but will exit the menu system */
|
||||
|
||||
uint8_t mui_u8g2_u8_chkbox_wm_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE, MUI_XY */
|
||||
uint8_t mui_u8g2_u8_radio_wm_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE,MUI_XYAT */
|
||||
|
||||
|
||||
|
||||
uint8_t mui_u8g2_u8_opt_line_wa_mse_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE,MUI_XYAT */
|
||||
uint8_t mui_u8g2_u8_opt_line_wa_mse_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE,MUI_XYAT */
|
||||
uint8_t mui_u8g2_u8_opt_line_wa_mud_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE,MUI_XYAT */
|
||||
uint8_t mui_u8g2_u8_opt_line_wa_mud_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE,MUI_XYAT */
|
||||
|
||||
/* dropdown list / combo box */
|
||||
/* The text part of the parent defines a '|' separated list of elements, which can be selected by the child. */
|
||||
/* Argument is a form number where the child element is placed multiple times */
|
||||
/* The child form does not require the ok button, because the child function will return to the parent with the select element */
|
||||
uint8_t mui_u8g2_u8_opt_parent_wm_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE, MUI_XYAT */
|
||||
uint8_t mui_u8g2_u8_opt_radio_child_wm_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE, MUI_XYA */
|
||||
uint8_t mui_u8g2_u8_opt_radio_child_w1_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE, MUI_XYA */
|
||||
uint8_t mui_u8g2_u8_opt_child_wm_pi(mui_t *ui, uint8_t msg); /* MUIF_VARIABLE, MUI_XYA */
|
||||
/* Note: there is no opt_child_goto muif, because this can be done with mui_u8g2_goto_form_w1_pi */
|
||||
|
||||
/* (scrollable) jump menu */
|
||||
/* The text part of the parent defines a '|' separated list of elements, which can be selected goto_form functions. */
|
||||
/* Each '|' separated element must be prefixed with the form number (MUI_x) */
|
||||
uint8_t mui_u8g2_goto_data(mui_t *ui, uint8_t msg); /* REF, MUIF_RO, MUI_DATA (WARNING: Must appear only once per form!!! */
|
||||
uint8_t mui_u8g2_goto_form_w1_pi(mui_t *ui, uint8_t msg); /* REF, MUIF_BUTTON, MUI_XYA */
|
||||
uint8_t mui_u8g2_goto_form_w1_pf(mui_t *ui, uint8_t msg); /* REF, MUIF_BUTTON, MUI_XYA */
|
||||
|
||||
|
||||
/* character input */
|
||||
uint8_t mui_u8g2_u8_char_wm_mud_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_VARIABLE,MUI_XY, usually requires a monospaced font line profont12 */
|
||||
|
||||
|
||||
/*===== MUIF U8g2 Label =====*/
|
||||
|
||||
#define MUIF_U8G2_LABEL() MUIF_LABEL(mui_u8g2_draw_text)
|
||||
|
||||
|
||||
/*===== data = u8g2 font data =====*/
|
||||
|
||||
//#define MUIF_U8G2_FONT_STYLE(n,font) MUIF("S" #n, 0, (void *)(font), mui_u8g2_set_font_style_function)
|
||||
#define MUIF_U8G2_FONT_STYLE(n, font) { 'S', #n[0], 0, 0, (void *)(font), mui_u8g2_set_font_style_function}
|
||||
|
||||
|
||||
uint8_t mui_u8g2_set_font_style_function(mui_t *ui, uint8_t msg);
|
||||
|
||||
|
||||
/*===== data = mui_u8g2_u8_min_max_t* =====*/
|
||||
|
||||
/* gcc note: the macro uses array compound literals to extend the lifetime in C++, see last section in https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html */
|
||||
#define MUIF_U8G2_U8_MIN_MAX(id, valptr, min, max, muif) \
|
||||
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
|
||||
(void *)((mui_u8g2_u8_min_max_t [] ) {{ (valptr) MUI_U8G2_COMMA (min) MUI_U8G2_COMMA (max)}}), \
|
||||
(muif))
|
||||
|
||||
uint8_t mui_u8g2_u8_min_max_wm_mse_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U8_MIN_MAX, MUI_XY */
|
||||
uint8_t mui_u8g2_u8_min_max_wm_mud_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U8_MIN_MAX, MUI_XY */
|
||||
|
||||
uint8_t mui_u8g2_u8_min_max_wm_mse_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U8_MIN_MAX, MUI_XY */
|
||||
uint8_t mui_u8g2_u8_min_max_wm_mud_pf(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U8_MIN_MAX, MUI_XY */
|
||||
|
||||
/*===== data = mui_u8g2_u8_min_max_step_t* =====*/
|
||||
|
||||
/* gcc note: the macro uses array compound literals to extend the lifetime in C++, see last section in https://gcc.gnu.org/onlinedocs/gcc/Compound-Literals.html */
|
||||
#define MUIF_U8G2_U8_MIN_MAX_STEP(id, valptr, min, max, step, flags, muif) \
|
||||
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
|
||||
(void *)((mui_u8g2_u8_min_max_step_t [] ) {{ (valptr) MUI_U8G2_COMMA (min) MUI_U8G2_COMMA (max) MUI_U8G2_COMMA (step) MUI_U8G2_COMMA (flags) }}), \
|
||||
(muif))
|
||||
|
||||
#define MUI_MMS_2X_BAR 0x01
|
||||
#define MUI_MMS_4X_BAR 0x02
|
||||
#define MUI_MMS_SHOW_VALUE 0x04
|
||||
|
||||
uint8_t mui_u8g2_u8_bar_wm_mse_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_bar_wm_mud_pi(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_bar_wm_mse_pf(mui_t *ui, uint8_t msg);
|
||||
uint8_t mui_u8g2_u8_bar_wm_mud_pf(mui_t *ui, uint8_t msg);
|
||||
|
||||
/*===== data = mui_u8g2_list_t* =====*/
|
||||
/* similar to mui_u8g2_u8_opt_line, but u16 and dynamic list */
|
||||
|
||||
|
||||
#define MUIF_U8G2_U16_LIST(id, valptr, dataptr, getcb, cntcb, muif) \
|
||||
MUIF(id, MUIF_CFLAG_IS_CURSOR_SELECTABLE, \
|
||||
(void *)((mui_u8g2_list_t [] ) {{ (valptr) MUI_U8G2_COMMA (dataptr) MUI_U8G2_COMMA (getcb) MUI_U8G2_COMMA (cntcb)}}), \
|
||||
(muif))
|
||||
|
||||
uint8_t mui_u8g2_u16_list_line_wa_mse_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_LIST, MUI_XYA, arg=pixel fieldsize */
|
||||
uint8_t mui_u8g2_u16_list_line_wa_mud_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_LIST, MUI_XYA, arg=pixel fieldsize */
|
||||
|
||||
|
||||
/* dropdown list / combo box with 16 size and callback functions for MUIF_U8G2_U16_LIST */
|
||||
uint8_t mui_u8g2_u16_list_parent_wm_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_LIST, MUI_XYA, arg=subform */
|
||||
uint8_t mui_u8g2_u16_list_child_w1_pi(mui_t *ui, uint8_t msg); /* GIF, MUIF_U8G2_U16_LIST, MUI_XYA, arg=sub element number */
|
||||
uint8_t mui_u8g2_u16_list_goto_w1_pi(mui_t *ui, uint8_t msg); /* REF, MUIF_U8G2_U16_LIST first char of the string denotes the target form */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* MUI_U8G2_H */
|
||||
|
||||
2900
Middlewares/u8g2Lib/inc/u8g2.h
Normal file
2900
Middlewares/u8g2Lib/inc/u8g2.h
Normal file
File diff suppressed because it is too large
Load Diff
1287
Middlewares/u8g2Lib/inc/u8x8.h
Normal file
1287
Middlewares/u8g2Lib/inc/u8x8.h
Normal file
File diff suppressed because it is too large
Load Diff
76
Middlewares/u8g2Lib/src/U8g2lib.cpp
Normal file
76
Middlewares/u8g2Lib/src/U8g2lib.cpp
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
|
||||
U8g2lib.cpp
|
||||
|
||||
Arduino specific functions
|
||||
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "U8g2lib.h"
|
||||
|
||||
#ifdef ARDUINO
|
||||
static Print *u8g2_print_for_screenshot;
|
||||
|
||||
void u8g2_print_callback(const char *s)
|
||||
{
|
||||
yield();
|
||||
u8g2_print_for_screenshot->print(s);
|
||||
}
|
||||
|
||||
void U8G2::writeBufferPBM(Print &p)
|
||||
{
|
||||
u8g2_print_for_screenshot = &p;
|
||||
u8g2_WriteBufferPBM(getU8g2(), u8g2_print_callback);
|
||||
}
|
||||
|
||||
void U8G2::writeBufferXBM(Print &p)
|
||||
{
|
||||
u8g2_print_for_screenshot = &p;
|
||||
u8g2_WriteBufferXBM(getU8g2(), u8g2_print_callback);
|
||||
}
|
||||
|
||||
void U8G2::writeBufferPBM2(Print &p)
|
||||
{
|
||||
u8g2_print_for_screenshot = &p;
|
||||
u8g2_WriteBufferPBM2(getU8g2(), u8g2_print_callback);
|
||||
}
|
||||
|
||||
void U8G2::writeBufferXBM2(Print &p)
|
||||
{
|
||||
u8g2_print_for_screenshot = &p;
|
||||
u8g2_WriteBufferXBM2(getU8g2(), u8g2_print_callback);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
1910
Middlewares/u8g2Lib/src/U8x8lib.cpp
Normal file
1910
Middlewares/u8g2Lib/src/U8x8lib.cpp
Normal file
File diff suppressed because it is too large
Load Diff
941
Middlewares/u8g2Lib/src/mui.c
Normal file
941
Middlewares/u8g2Lib/src/mui.c
Normal file
@ -0,0 +1,941 @@
|
||||
/*
|
||||
|
||||
mui.c
|
||||
|
||||
Monochrome minimal user interface: Core library.
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2021, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
|
||||
"mui.c" is a graphical user interface, developed as part of u8g2.
|
||||
However "mui.c" is independent of u8g2 and can be used without u8g2 code.
|
||||
The glue code between "mui.c" and u8g2 is located in "mui_u8g2.c"
|
||||
|
||||
c: cmd
|
||||
i: ID0
|
||||
j: ID1
|
||||
xy: Position (x and y)
|
||||
/text/: some text. The text can start with any delimiter (except 0 and |), but also has to end with the same delimiter
|
||||
a: Single char argument
|
||||
u: Single char argument with the user interface form number
|
||||
|
||||
"Uu" the interface --> no ID
|
||||
|
||||
Manual ID:
|
||||
"Fijxy" Generic field: Places field with id ii at x/y --> ID=ij
|
||||
"Bijxy/text/" Generic field (Button) with Text --> ID=ij
|
||||
"Tiixya/text/" Generic field with argument and text --> ID = ij
|
||||
"Aiixya"
|
||||
|
||||
Fixed ID:
|
||||
"Si" the style --> ID=@i
|
||||
"Lxy/labeltext/" Places a text at the specified position, field with - -> ID=.L, .l
|
||||
"Gxyu/menutext/" Go to the specified menu without placing the user interface form on the stack --> ID=.G, .g
|
||||
|
||||
|
||||
cijxy
|
||||
cijxy/text/
|
||||
cijxya/text/
|
||||
|
||||
cxy/text/
|
||||
cxya/text/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "mui.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//#define mui_get_fds_char(s) ((uint8_t)(*s))
|
||||
|
||||
//#include <stdio.h>
|
||||
//#define MUI_DEBUG(...) printf(__VA_ARGS__)
|
||||
#define MUI_DEBUG(...)
|
||||
|
||||
uint8_t mui_get_fds_char(fds_t *s)
|
||||
{
|
||||
//return (uint8_t)(*s);
|
||||
return (uint8_t)mui_pgm_read(s);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
s must point to a valid command within FDS
|
||||
*/
|
||||
static size_t mui_fds_get_cmd_size_without_text(fds_t *s) MUI_NOINLINE;
|
||||
static size_t mui_fds_get_cmd_size_without_text(fds_t *s)
|
||||
{
|
||||
uint8_t c = mui_get_fds_char(s);
|
||||
c &= 0xdf; /* consider upper and lower case */
|
||||
switch(c)
|
||||
{
|
||||
case 'U': return 2; // User Form: CMD (1 Byte), Form-Id (1 Byte)
|
||||
case 'S': return 2; // Style: CMD (1 Byte), Style Id (1 Byte)
|
||||
case 'D': return 3; // Data within Text: CMD (1 Byte), ID (2 Bytes), Text (does not count here)
|
||||
case 'Z': return 3; // Zero field without x, y, arg & text: CMD (1 Byte), ID (2 Bytes)
|
||||
case 'F': return 5; // Field without arg & text: CMD (1 Byte), ID (2 Bytes), X, Y
|
||||
case 'B': return 5; // Field with text: CMD (1 Byte), ID (2 Bytes), X, Y, Text (does not count here)
|
||||
case 'T': return 6; // Field with arg & text: CMD (1 Byte), ID (2 Bytes), X, Y, Arg, Text (does not count here)
|
||||
case 'A': return 6; // Field with arg (no text): CMD (1 Byte), ID (2 Bytes), X, Y, Arg, Text
|
||||
case 'L': return 3; // Text Label: CMD (1 Byte), X, Y (same as 'B' but with fixed ID '.L', MUIF_LABEL, MUI_LABEL)
|
||||
case 'G': return 4; // Goto Btutton: CMD (1Byte), X, Y, Arg, Text (same as 'T' but with fixed ID '.G', MUIF_GOTO, MUI_GOTO)
|
||||
case 0: return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
s must point to the string delimiter start: first '/' for "B00ab/ok/"
|
||||
- '/' actually is 0xff
|
||||
- return the total size of the string, including the delimiter
|
||||
- copies the content of the string ("ok") to the ui text buffer
|
||||
|
||||
*/
|
||||
static size_t mui_fds_parse_text(mui_t *ui, fds_t *s)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
ui->delimiter = mui_get_fds_char(s);
|
||||
uint8_t c;
|
||||
fds_t *t = s;
|
||||
|
||||
//printf("mui_fds_parse_text del=%d\n", delimiter);
|
||||
#ifdef MUI_CHECK_EOFDS
|
||||
if ( ui->delimiter == 0 )
|
||||
return 0;
|
||||
#endif
|
||||
t++;
|
||||
for( ;; )
|
||||
{
|
||||
c = mui_get_fds_char(t);
|
||||
//printf("mui_fds_parse_text i=%d, c=%c\n", i, c);
|
||||
#ifdef MUI_CHECK_EOFDS
|
||||
if ( c == 0 )
|
||||
break;
|
||||
#endif
|
||||
if ( c == ui->delimiter )
|
||||
{
|
||||
t++;
|
||||
break;
|
||||
}
|
||||
if ( i < MUI_MAX_TEXT_LEN )
|
||||
{
|
||||
ui->text[i++] = c;
|
||||
}
|
||||
t++;
|
||||
}
|
||||
ui->text[i] = '\0' ;
|
||||
return t-s;
|
||||
}
|
||||
|
||||
/*
|
||||
get the first token within a text argument.
|
||||
The text argument may look like this:
|
||||
"B00ab/banana|apple|peach|cherry/"
|
||||
The outer delimiter "/" is not fixed and can be any char except "|" and "\0"
|
||||
The inner delimiter "|" is fixed. It must be the pipe symbol.
|
||||
This function will place "banana" into ui->text if the result is not 0
|
||||
|
||||
if ( mui_fds_first_token(ui) )
|
||||
{
|
||||
do
|
||||
{
|
||||
// handle token in ui->text
|
||||
} while ( mui_fds_next_token(ui) )
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
uint8_t mui_fds_first_token(mui_t *ui)
|
||||
{
|
||||
ui->token = ui->fds;
|
||||
ui->token += mui_fds_get_cmd_size_without_text(ui->fds);
|
||||
ui->delimiter = mui_get_fds_char(ui->token);
|
||||
ui->token++; // place ui->token on the first char of the token
|
||||
return mui_fds_next_token(ui);
|
||||
}
|
||||
|
||||
/*
|
||||
The inner token delimiter "|" is fixed. It must be the pipe symbol.
|
||||
*/
|
||||
uint8_t mui_fds_next_token(mui_t *ui)
|
||||
{
|
||||
uint8_t c;
|
||||
uint8_t i = 0;
|
||||
// printf("mui_fds_next_token: call, ui->token=%p\n", ui->token);
|
||||
for( ;; )
|
||||
{
|
||||
c = mui_get_fds_char(ui->token);
|
||||
// printf("mui_fds_next_token: i=%d c=%c\n", i, c);
|
||||
#ifdef MUI_CHECK_EOFDS
|
||||
if ( c == 0 )
|
||||
break;
|
||||
#endif
|
||||
if ( c == ui->delimiter )
|
||||
break;
|
||||
if ( c == '|' )
|
||||
{
|
||||
ui->token++; // place ui->token on the first char of the next token
|
||||
break;
|
||||
}
|
||||
|
||||
if ( i < MUI_MAX_TEXT_LEN )
|
||||
{
|
||||
ui->text[i++] = c;
|
||||
}
|
||||
|
||||
ui->token++;
|
||||
}
|
||||
ui->text[i] = '\0' ;
|
||||
if ( i == 0 )
|
||||
return 0; // no further token found
|
||||
return 1; // token placed in ui->text
|
||||
}
|
||||
|
||||
/*
|
||||
find nth token ('|' delimiter), return 0 if n exceeds the number of tokens, 1 otherwise
|
||||
the result is stored in ui->text
|
||||
*/
|
||||
uint8_t mui_fds_get_nth_token(mui_t *ui, uint8_t n)
|
||||
{
|
||||
// printf("mui_fds_get_nth_token: call, n=%d\n", n);
|
||||
if ( mui_fds_first_token(ui) )
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( n == 0 )
|
||||
{
|
||||
// printf("mui_fds_get_nth_token: found");
|
||||
return 1;
|
||||
}
|
||||
n--;
|
||||
} while ( mui_fds_next_token(ui) );
|
||||
}
|
||||
//printf("mui_fds_get_nth_token: NOT found\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t mui_fds_get_token_cnt(mui_t *ui)
|
||||
{
|
||||
uint8_t n = 0;
|
||||
if ( mui_fds_first_token(ui) )
|
||||
{
|
||||
do
|
||||
{
|
||||
n++;
|
||||
} while ( mui_fds_next_token(ui) );
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
#define mui_fds_is_text(c) ( (c) == 'U' || (c) == 'S' || (c) == 'F' || (c) == 'A' || (c) == 'Z' ? 0 : 1 )
|
||||
|
||||
/*
|
||||
s must point to a valid command within FDS
|
||||
return
|
||||
The complete length of the command (including any text part)
|
||||
sideeffect:
|
||||
Any existing text part will be copied into ui->text
|
||||
ui->text will be assigned to empty string if there is no text argument
|
||||
*/
|
||||
static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s) MUI_NOINLINE;
|
||||
static size_t mui_fds_get_cmd_size(mui_t *ui, fds_t *s)
|
||||
{
|
||||
size_t l = mui_fds_get_cmd_size_without_text(s);
|
||||
uint8_t c = mui_get_fds_char(s);
|
||||
ui->text[0] = '\0' ; /* always reset the text buffer */
|
||||
if ( mui_fds_is_text(c) )
|
||||
{
|
||||
l += mui_fds_parse_text(ui, s+l);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
mui_Init() will setup the menu system but will not activate or display anything.
|
||||
Use mui_GotoForm() after this command, then use mui_Draw() to draw the menu on a display.
|
||||
*/
|
||||
void mui_Init(mui_t *ui, void *graphics_data, fds_t *fds, muif_t *muif_tlist, size_t muif_tcnt)
|
||||
{
|
||||
memset(ui, 0, sizeof(mui_t));
|
||||
ui->root_fds = fds;
|
||||
//ui->current_form_fds = NULL; // not required, because there was a memset before
|
||||
ui->muif_tlist = muif_tlist;
|
||||
ui->muif_tcnt = muif_tcnt;
|
||||
ui->graphics_data = graphics_data;
|
||||
}
|
||||
|
||||
int mui_find_uif(mui_t *ui, uint8_t id0, uint8_t id1)
|
||||
{
|
||||
size_t i;
|
||||
for( i = 0; i < ui->muif_tcnt; i++ )
|
||||
{
|
||||
/*
|
||||
if ( ui->muif_tlist[i].id0 == id0 )
|
||||
if ( ui->muif_tlist[i].id1 == id1 )
|
||||
return i;
|
||||
*/
|
||||
if ( muif_get_id0(ui->muif_tlist+i) == id0 )
|
||||
if ( muif_get_id1(ui->muif_tlist+i) == id1 )
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
assumes a valid position in ui->fds and calculates all the other variables
|
||||
some fields are always calculated like the ui->cmd and ui->len field
|
||||
other member vars are calculated only if the return value is 1
|
||||
will return 1 if the field id was found.
|
||||
will return 0 if the field id was not found in uif or if ui->fds points to something else than a field
|
||||
*/
|
||||
static uint8_t mui_prepare_current_field(mui_t *ui) MUI_NOINLINE;
|
||||
static uint8_t mui_prepare_current_field(mui_t *ui)
|
||||
{
|
||||
int muif_tidx;
|
||||
|
||||
ui->uif = NULL;
|
||||
ui->dflags = 0;
|
||||
ui->id0 = 0;
|
||||
ui->id1 = 0;
|
||||
ui->arg = 0;
|
||||
|
||||
/* calculate the length of the command and copy the text argument */
|
||||
/* this will also clear the text in cases where there is no text argument */
|
||||
ui->len = mui_fds_get_cmd_size(ui, ui->fds);
|
||||
//printf("mui_prepare_current_field len=%d\n", ui->len);
|
||||
|
||||
/* get the command and check whether end of form is reached */
|
||||
ui->cmd = mui_get_fds_char(ui->fds);
|
||||
//printf("mui_prepare_current_field cmd='%c' len=%d\n", ui->cmd, ui->len);
|
||||
|
||||
/* Copy the cmd also to second id value. This is required for some commands, others will overwrite this below */
|
||||
ui->id1 = ui->cmd;
|
||||
|
||||
/* now make the command uppercase so that both, upper and lower case are considered */
|
||||
ui->cmd &= 0xdf; /* consider upper and lower case */
|
||||
|
||||
if ( ui->cmd == 'U' || ui->cmd == 0 )
|
||||
return 0;
|
||||
|
||||
/* calculate the dynamic flags */
|
||||
if ( ui->fds == ui->cursor_focus_fds )
|
||||
ui->dflags |= MUIF_DFLAG_IS_CURSOR_FOCUS;
|
||||
if ( ui->fds == ui->touch_focus_fds )
|
||||
ui->dflags |= MUIF_DFLAG_IS_TOUCH_FOCUS;
|
||||
|
||||
|
||||
/* get the id0 and id1 values */
|
||||
if ( ui->cmd == 'F' || ui->cmd == 'B' || ui->cmd == 'T' || ui->cmd == 'A' )
|
||||
{
|
||||
ui->id0 = mui_get_fds_char(ui->fds+1);
|
||||
ui->id1 = mui_get_fds_char(ui->fds+2);
|
||||
ui->x = mui_get_fds_char(ui->fds+3);
|
||||
ui->y = mui_get_fds_char(ui->fds+4);
|
||||
if ( ui->cmd == 'A' || ui->cmd == 'T' )
|
||||
{
|
||||
ui->arg = mui_get_fds_char(ui->fds+5);
|
||||
}
|
||||
}
|
||||
else if ( ui->cmd == 'D' || ui->cmd == 'Z' )
|
||||
{
|
||||
ui->id0 = mui_get_fds_char(ui->fds+1);
|
||||
ui->id1 = mui_get_fds_char(ui->fds+2);
|
||||
}
|
||||
else if ( ui->cmd == 'S' )
|
||||
{
|
||||
ui->id0 = 'S';
|
||||
ui->id1 = mui_get_fds_char(ui->fds+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->id0 = '.';
|
||||
/* note that ui->id1 contains the original cmd value */
|
||||
ui->x = mui_get_fds_char(ui->fds+1);
|
||||
ui->y = mui_get_fds_char(ui->fds+2);
|
||||
if ( ui->cmd == 'G' || ui->cmd == 'M' ) /* this is also true for 'g' or 'm' */
|
||||
{
|
||||
ui->arg = mui_get_fds_char(ui->fds+3);
|
||||
}
|
||||
}
|
||||
|
||||
//MUI_DEBUG("mui_prepare_current_field cmd='%c' len=%d arg=%d\n", ui->cmd, ui->len, ui->arg);
|
||||
|
||||
|
||||
/* find the field */
|
||||
muif_tidx = mui_find_uif(ui, ui->id0, ui->id1);
|
||||
//printf("mui_prepare_current_field: muif_tidx=%d\n", muif_tidx);
|
||||
if ( muif_tidx >= 0 )
|
||||
{
|
||||
ui->uif = ui->muif_tlist + muif_tidx;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
assumes that ui->fds has been assigned correctly
|
||||
and that ui->target_fds and ui->tmp_fds had been cleared if required
|
||||
|
||||
Usually do not call this function directly, instead use mui_loop_over_form
|
||||
|
||||
*/
|
||||
|
||||
static void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
|
||||
static void mui_inner_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
|
||||
{
|
||||
uint8_t cmd;
|
||||
|
||||
//MUI_DEBUG("mui_inner_loop_over_form start %p\n", task);
|
||||
|
||||
ui->fds += mui_fds_get_cmd_size(ui, ui->fds); // skip the first entry, it is U always
|
||||
for(;;)
|
||||
{
|
||||
//printf("fds=%p *fds='%c'\n", ui->fds, ui->fds[0]);
|
||||
/* get the command and check whether end of form is reached */
|
||||
cmd = mui_get_fds_char(ui->fds);
|
||||
if ( cmd == 'U' || cmd == 0 )
|
||||
break;
|
||||
if ( mui_prepare_current_field(ui) ) /* side effect: calculate ui->len */
|
||||
if ( task(ui) ) /* call the task, which was provided as argument to this function */
|
||||
{
|
||||
//MUI_DEBUG("mui_inner_loop_over_form break by task\n");
|
||||
break;
|
||||
}
|
||||
ui->fds += ui->len;
|
||||
}
|
||||
|
||||
//MUI_DEBUG("mui_inner_loop_over_form end %p\n", task);
|
||||
}
|
||||
|
||||
static void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui)) MUI_NOINLINE;
|
||||
static void mui_loop_over_form(mui_t *ui, uint8_t (*task)(mui_t *ui))
|
||||
{
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
ui->fds = ui->current_form_fds;
|
||||
ui->target_fds = NULL;
|
||||
ui->tmp_fds = NULL;
|
||||
|
||||
mui_inner_loop_over_form(ui, task);
|
||||
}
|
||||
|
||||
/*
|
||||
n is the form number
|
||||
*/
|
||||
fds_t *mui_find_form(mui_t *ui, uint8_t n)
|
||||
{
|
||||
fds_t *fds = ui->root_fds;
|
||||
uint8_t cmd;
|
||||
|
||||
for( ;; )
|
||||
{
|
||||
cmd = mui_get_fds_char(fds);
|
||||
if ( cmd == 0 )
|
||||
break;
|
||||
if ( cmd == 'U' )
|
||||
{
|
||||
if ( mui_get_fds_char(fds+1) == n )
|
||||
{
|
||||
return fds;
|
||||
}
|
||||
/* not found, just coninue */
|
||||
}
|
||||
|
||||
fds += mui_fds_get_cmd_size(ui, fds);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* === task procedures (arguments for mui_loop_over_form) === */
|
||||
/* ui->fds contains the current field */
|
||||
|
||||
uint8_t mui_task_draw(mui_t *ui)
|
||||
{
|
||||
//printf("mui_task_draw fds=%p uif=%p text=%s\n", ui->fds, ui->uif, ui->text);
|
||||
muif_get_cb(ui->uif)(ui, MUIF_MSG_DRAW);
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_form_start(mui_t *ui)
|
||||
{
|
||||
muif_get_cb(ui->uif)(ui, MUIF_MSG_FORM_START);
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_form_end(mui_t *ui)
|
||||
{
|
||||
muif_get_cb(ui->uif)(ui, MUIF_MSG_FORM_END);
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
static uint8_t mui_uif_is_cursor_selectable(mui_t *ui) MUI_NOINLINE;
|
||||
static uint8_t mui_uif_is_cursor_selectable(mui_t *ui)
|
||||
{
|
||||
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t mui_task_find_prev_cursor_uif(mui_t *ui)
|
||||
{
|
||||
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
if ( mui_uif_is_cursor_selectable(ui) )
|
||||
{
|
||||
if ( ui->fds == ui->cursor_focus_fds )
|
||||
{
|
||||
ui->target_fds = ui->tmp_fds;
|
||||
return 1; /* stop looping */
|
||||
}
|
||||
ui->tmp_fds = ui->fds;
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_find_first_cursor_uif(mui_t *ui)
|
||||
{
|
||||
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
if ( mui_uif_is_cursor_selectable(ui) )
|
||||
{
|
||||
// if ( ui->target_fds == NULL )
|
||||
// {
|
||||
ui->target_fds = ui->fds;
|
||||
return 1; /* stop looping */
|
||||
// }
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_find_last_cursor_uif(mui_t *ui)
|
||||
{
|
||||
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
if ( mui_uif_is_cursor_selectable(ui) )
|
||||
{
|
||||
//ui->cursor_focus_position++;
|
||||
ui->target_fds = ui->fds;
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_find_next_cursor_uif(mui_t *ui)
|
||||
{
|
||||
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
if ( mui_uif_is_cursor_selectable(ui) )
|
||||
{
|
||||
if ( ui->tmp_fds != NULL )
|
||||
{
|
||||
ui->target_fds = ui->fds;
|
||||
ui->tmp_fds = NULL;
|
||||
return 1; /* stop looping */
|
||||
}
|
||||
if ( ui->fds == ui->cursor_focus_fds )
|
||||
{
|
||||
ui->tmp_fds = ui->fds;
|
||||
}
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_get_current_cursor_focus_position(mui_t *ui)
|
||||
{
|
||||
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
if ( mui_uif_is_cursor_selectable(ui) )
|
||||
{
|
||||
if ( ui->fds == ui->cursor_focus_fds )
|
||||
return 1; /* stop looping */
|
||||
ui->tmp8++;
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_read_nth_selectable_field(mui_t *ui)
|
||||
{
|
||||
//if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_CURSOR_SELECTABLE )
|
||||
if ( mui_uif_is_cursor_selectable(ui) )
|
||||
{
|
||||
if ( ui->tmp8 == 0 )
|
||||
return 1; /* stop looping */
|
||||
ui->tmp8--;
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
uint8_t mui_task_find_execute_on_select_field(mui_t *ui)
|
||||
{
|
||||
if ( muif_get_cflags(ui->uif) & MUIF_CFLAG_IS_EXECUTE_ON_SELECT )
|
||||
{
|
||||
ui->target_fds = ui->fds;
|
||||
return 1; /* stop looping */
|
||||
}
|
||||
return 0; /* continue with the loop */
|
||||
}
|
||||
|
||||
|
||||
/* === utility functions for the user API === */
|
||||
|
||||
static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg) MUI_NOINLINE;
|
||||
static uint8_t mui_send_cursor_msg(mui_t *ui, uint8_t msg)
|
||||
{
|
||||
if ( ui->cursor_focus_fds )
|
||||
{
|
||||
ui->fds = ui->cursor_focus_fds;
|
||||
if ( mui_prepare_current_field(ui) )
|
||||
return muif_get_cb(ui->uif)(ui, msg);
|
||||
}
|
||||
return 0; /* not called, msg not handled */
|
||||
}
|
||||
|
||||
/* === user API === */
|
||||
|
||||
/*
|
||||
returns the field pos which has the current focus
|
||||
If the first selectable field has the focus, then 0 will be returned
|
||||
Unselectable fields (for example labels) are skipped by this count.
|
||||
If no fields are selectable, then 0 is returned
|
||||
|
||||
The return value can be used as last argument for mui_EnterForm or mui_GotoForm
|
||||
|
||||
WARNING: This function will destroy current fds and field information.
|
||||
*/
|
||||
uint8_t mui_GetCurrentCursorFocusPosition(mui_t *ui)
|
||||
{
|
||||
//fds_t *fds = ui->fds;
|
||||
ui->tmp8 = 0;
|
||||
mui_loop_over_form(ui, mui_task_get_current_cursor_focus_position);
|
||||
//ui->fds = fds;
|
||||
return ui->tmp8;
|
||||
}
|
||||
|
||||
|
||||
void mui_Draw(mui_t *ui)
|
||||
{
|
||||
mui_loop_over_form(ui, mui_task_draw);
|
||||
}
|
||||
|
||||
void mui_next_field(mui_t *ui)
|
||||
{
|
||||
mui_loop_over_form(ui, mui_task_find_next_cursor_uif);
|
||||
// ui->cursor_focus_position++;
|
||||
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
||||
if ( ui->target_fds == NULL )
|
||||
{
|
||||
mui_loop_over_form(ui, mui_task_find_first_cursor_uif);
|
||||
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
||||
// ui->cursor_focus_position = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
this function will overwrite the ui field related member variables
|
||||
nth_token can be 0 if the fiel text is not a option list
|
||||
the result is stored in ui->text
|
||||
|
||||
token delimiter is '|' (pipe symbol)
|
||||
|
||||
fds: The start of a field (MUI_DATA)
|
||||
nth_token: The position of the token, which should be returned
|
||||
*/
|
||||
uint8_t mui_GetSelectableFieldTextOption(mui_t *ui, fds_t *fds, uint8_t nth_token)
|
||||
{
|
||||
fds_t *fds_backup = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
||||
int len = ui->len; // backup length of the current command, 26 sep 2021: probably this is not required any more
|
||||
uint8_t is_found;
|
||||
|
||||
ui->fds = fds;
|
||||
// at this point ui->fds contains the field which contains the tokens
|
||||
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
|
||||
is_found = mui_fds_get_nth_token(ui, nth_token); // return value is ignored here
|
||||
|
||||
ui->fds = fds_backup; // restore the previous fds position
|
||||
ui->len = len;
|
||||
// result is stored in ui->text
|
||||
return is_found;
|
||||
}
|
||||
|
||||
uint8_t mui_GetSelectableFieldOptionCnt(mui_t *ui, fds_t *fds)
|
||||
{
|
||||
fds_t *fds_backup = ui->fds; // backup the current fds, so that this function can be called inside a task loop
|
||||
int len = ui->len; // backup length of the current command 26 sep 2021: probably this is not required any more
|
||||
uint8_t cnt = 0;
|
||||
|
||||
ui->fds = fds;
|
||||
// at this point ui->fds contains the field which contains the tokens
|
||||
// now get the opion string out of the text field. nth_token can be 0 if this is no opion string
|
||||
cnt = mui_fds_get_token_cnt(ui);
|
||||
|
||||
ui->fds = fds_backup; // restore the previous fds position
|
||||
ui->len = len;
|
||||
// result is stored in ui->text
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//static void mui_send_cursor_enter_msg(mui_t *ui) MUI_NOINLINE;
|
||||
static uint8_t mui_send_cursor_enter_msg(mui_t *ui)
|
||||
{
|
||||
ui->is_mud = 0;
|
||||
return mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_ENTER);
|
||||
}
|
||||
|
||||
/*
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
mui_EnterForm is similar to mui_GotoForm and differes only in the second argument (which is the form id instead of the fds pointer)
|
||||
*/
|
||||
void mui_EnterForm(mui_t *ui, fds_t *fds, uint8_t initial_cursor_position)
|
||||
{
|
||||
/* exit any previous form, will not do anything if there is no current form */
|
||||
mui_LeaveForm(ui);
|
||||
|
||||
/* clean focus fields */
|
||||
ui->touch_focus_fds = NULL;
|
||||
ui->cursor_focus_fds = NULL;
|
||||
|
||||
/* reset all the scoll values */
|
||||
ui->form_scroll_top = 0;
|
||||
ui->form_scroll_visible = 0;
|
||||
ui->form_scroll_total = 0;
|
||||
|
||||
/* assign the form, which should be entered */
|
||||
ui->current_form_fds = fds;
|
||||
|
||||
/* inform all fields that we start a new form */
|
||||
MUI_DEBUG("mui_EnterForm: form_start, initial_cursor_position=%d\n", initial_cursor_position);
|
||||
mui_loop_over_form(ui, mui_task_form_start);
|
||||
|
||||
/* assign initional cursor focus */
|
||||
MUI_DEBUG("mui_EnterForm: find_first_cursor_uif\n");
|
||||
mui_loop_over_form(ui, mui_task_find_first_cursor_uif);
|
||||
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
||||
MUI_DEBUG("mui_EnterForm: find_first_cursor_uif target_fds=%p\n", ui->target_fds);
|
||||
|
||||
while( initial_cursor_position > 0 )
|
||||
{
|
||||
mui_NextField(ui); // mui_next_field(ui) is not sufficient in case of scrolling
|
||||
initial_cursor_position--;
|
||||
}
|
||||
|
||||
while( mui_send_cursor_enter_msg(ui) == 255 )
|
||||
{
|
||||
mui_NextField(ui); // mui_next_field(ui) is not sufficient in case of scrolling
|
||||
}
|
||||
}
|
||||
|
||||
/* input: current_form_fds */
|
||||
/*
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
*/
|
||||
void mui_LeaveForm(mui_t *ui)
|
||||
{
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
||||
ui->cursor_focus_fds = NULL;
|
||||
|
||||
/* inform all fields that we leave the form */
|
||||
MUI_DEBUG("mui_LeaveForm: form_end\n");
|
||||
mui_loop_over_form(ui, mui_task_form_end);
|
||||
ui->current_form_fds = NULL;
|
||||
}
|
||||
|
||||
/* 0: error, form not found */
|
||||
/*
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
*/
|
||||
uint8_t mui_GotoForm(mui_t *ui, uint8_t form_id, uint8_t initial_cursor_position)
|
||||
{
|
||||
fds_t *fds = mui_find_form(ui, form_id);
|
||||
if ( fds == NULL )
|
||||
return 0;
|
||||
/* EnterForm will also leave any previous form */
|
||||
mui_EnterForm(ui, fds, initial_cursor_position);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mui_SaveForm(mui_t *ui)
|
||||
{
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return;
|
||||
|
||||
ui->last_form_fds = ui->cursor_focus_fds;
|
||||
ui->last_form_id = mui_get_fds_char(ui->current_form_fds+1);
|
||||
ui->last_form_cursor_focus_position = mui_GetCurrentCursorFocusPosition(ui);
|
||||
}
|
||||
|
||||
/*
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
*/
|
||||
void mui_RestoreForm(mui_t *ui)
|
||||
{
|
||||
mui_GotoForm(ui, ui->last_form_id, ui->last_form_cursor_focus_position);
|
||||
}
|
||||
|
||||
/*
|
||||
Save a cursor position for mui_GotoFormAutoCursorPosition command
|
||||
Two such positions is stored.
|
||||
*/
|
||||
void mui_SaveCursorPosition(mui_t *ui, uint8_t cursor_position)
|
||||
{
|
||||
uint8_t form_id = mui_get_fds_char(ui->current_form_fds+1);
|
||||
MUI_DEBUG("mui_SaveCursorPosition form_id=%d cursor_position=%d\n", form_id, cursor_position);
|
||||
|
||||
if ( form_id == ui->menu_form_id[0] )
|
||||
ui->menu_form_last_added = 0;
|
||||
else if ( form_id == ui->menu_form_id[1] )
|
||||
ui->menu_form_last_added = 1;
|
||||
else
|
||||
ui->menu_form_last_added ^= 1;
|
||||
ui->menu_form_id[ui->menu_form_last_added] = form_id;
|
||||
ui->menu_form_cursor_focus_position[ui->menu_form_last_added] = cursor_position;
|
||||
MUI_DEBUG("mui_SaveCursorPosition ui->menu_form_last_added=%d \n", ui->menu_form_last_added);
|
||||
}
|
||||
|
||||
/*
|
||||
Similar to mui_GotoForm, but will jump to previously stored cursor location (mui_SaveCursorPosition) or 0 if the cursor position was not saved.
|
||||
*/
|
||||
uint8_t mui_GotoFormAutoCursorPosition(mui_t *ui, uint8_t form_id)
|
||||
{
|
||||
uint8_t cursor_position = 0;
|
||||
if ( form_id == ui->menu_form_id[0] )
|
||||
cursor_position = ui->menu_form_cursor_focus_position[0];
|
||||
if ( form_id == ui->menu_form_id[1] )
|
||||
cursor_position = ui->menu_form_cursor_focus_position[1];
|
||||
MUI_DEBUG("mui_GotoFormAutoCursorPosition form_id=%d cursor_position=%d\n", form_id, cursor_position);
|
||||
return mui_GotoForm(ui, form_id, cursor_position);
|
||||
}
|
||||
|
||||
/*
|
||||
return current form id or -1 if the menu system is inactive
|
||||
*/
|
||||
int mui_GetCurrentFormId(mui_t *ui)
|
||||
{
|
||||
if ( mui_IsFormActive(ui) == 0 )
|
||||
return -1;
|
||||
return mui_get_fds_char(ui->current_form_fds+1);
|
||||
}
|
||||
|
||||
/*
|
||||
updates "ui->cursor_focus_fds"
|
||||
*/
|
||||
/*
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
*/
|
||||
void mui_NextField(mui_t *ui)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_NEXT) )
|
||||
return;
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
||||
mui_next_field(ui);
|
||||
} while ( mui_send_cursor_enter_msg(ui) == 255 );
|
||||
}
|
||||
|
||||
/*
|
||||
updates "ui->cursor_focus_fds"
|
||||
*/
|
||||
/*
|
||||
if called from a field function, then the current field variables are destroyed, so that call should be the last call in the field callback.
|
||||
*/
|
||||
void mui_PrevField(mui_t *ui)
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( mui_send_cursor_msg(ui, MUIF_MSG_EVENT_PREV) )
|
||||
return;
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
||||
|
||||
mui_loop_over_form(ui, mui_task_find_prev_cursor_uif);
|
||||
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
||||
if ( ui->target_fds == NULL )
|
||||
{
|
||||
//ui->cursor_focus_position = 0;
|
||||
mui_loop_over_form(ui, mui_task_find_last_cursor_uif);
|
||||
ui->cursor_focus_fds = ui->target_fds; // NULL is ok
|
||||
}
|
||||
} while( mui_send_cursor_enter_msg(ui) == 255 );
|
||||
}
|
||||
|
||||
|
||||
void mui_SendSelect(mui_t *ui)
|
||||
{
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_SELECT);
|
||||
}
|
||||
|
||||
/*
|
||||
Same as mui_SendSelect(), but will try to find a field, which is marked as "execute on select" (MUIF_EXECUTE_ON_SELECT_BUTTON).
|
||||
If such a field exists, then this field is executed, otherwise the current field will receive the select message.
|
||||
|
||||
MUIF_EXECUTE_ON_SELECT_BUTTON is set by muif macro MUIF_EXECUTE_ON_SELECT_BUTTON
|
||||
|
||||
used by MUIInputVersatileRotaryEncoder.ino example
|
||||
*/
|
||||
void mui_SendSelectWithExecuteOnSelectFieldSearch(mui_t *ui)
|
||||
{
|
||||
mui_loop_over_form(ui, mui_task_find_execute_on_select_field); /* Is there a exec on select field? */
|
||||
if ( ui->target_fds != NULL ) /* yes, found, ui->fds already points to the field */
|
||||
{
|
||||
fds_t *exec_on_select_field = ui->target_fds;
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_LEAVE);
|
||||
ui->cursor_focus_fds = exec_on_select_field; /* more cursor on the "exec on select" field */
|
||||
mui_send_cursor_enter_msg(ui);
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_SELECT);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* no "exec on select" field found, just send the select message to the field */
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_CURSOR_SELECT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mui_SendValueIncrement(mui_t *ui)
|
||||
{
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_VALUE_INCREMENT);
|
||||
}
|
||||
|
||||
void mui_SendValueDecrement(mui_t *ui)
|
||||
{
|
||||
mui_send_cursor_msg(ui, MUIF_MSG_VALUE_DECREMENT);
|
||||
}
|
||||
2178
Middlewares/u8g2Lib/src/mui_u8g2.c
Normal file
2178
Middlewares/u8g2Lib/src/mui_u8g2.c
Normal file
File diff suppressed because it is too large
Load Diff
218
Middlewares/u8g2Lib/src/u8g2_bitmap.c
Normal file
218
Middlewares/u8g2Lib/src/u8g2_bitmap.c
Normal file
@ -0,0 +1,218 @@
|
||||
/*
|
||||
|
||||
u8g2_bitmap.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
|
||||
void u8g2_SetBitmapMode(u8g2_t *u8g2, uint8_t is_transparent) {
|
||||
u8g2->bitmap_transparency = is_transparent;
|
||||
}
|
||||
|
||||
/*
|
||||
x,y Position on the display
|
||||
len Length of bitmap line in pixel. Note: This differs from u8glib which had a bytecount here.
|
||||
b Pointer to the bitmap line.
|
||||
Only draw pixels which are set.
|
||||
*/
|
||||
|
||||
void u8g2_DrawHorizontalBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t color = u8g2->draw_color;
|
||||
uint8_t ncolor = (color == 0 ? 1 : 0);
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
mask = 128;
|
||||
while(len > 0)
|
||||
{
|
||||
if ( *b & mask ) {
|
||||
u8g2->draw_color = color;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
} else if ( u8g2->bitmap_transparency == 0 ) {
|
||||
u8g2->draw_color = ncolor;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
x++;
|
||||
mask >>= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 128;
|
||||
b++;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
u8g2->draw_color = color;
|
||||
}
|
||||
|
||||
|
||||
/* u8glib compatible bitmap draw function */
|
||||
void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_uint_t w;
|
||||
w = cnt;
|
||||
w *= 8;
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
while( h > 0 )
|
||||
{
|
||||
u8g2_DrawHorizontalBitmap(u8g2, x, y, w, bitmap);
|
||||
bitmap += cnt;
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void u8g2_DrawHXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t color = u8g2->draw_color;
|
||||
uint8_t ncolor = (color == 0 ? 1 : 0);
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
mask = 1;
|
||||
while(len > 0) {
|
||||
if ( *b & mask ) {
|
||||
u8g2->draw_color = color;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
} else if ( u8g2->bitmap_transparency == 0 ) {
|
||||
u8g2->draw_color = ncolor;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
x++;
|
||||
mask <<= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 1;
|
||||
b++;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
u8g2->draw_color = color;
|
||||
}
|
||||
|
||||
|
||||
void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_uint_t blen;
|
||||
blen = w;
|
||||
blen += 7;
|
||||
blen >>= 3;
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
while( h > 0 )
|
||||
{
|
||||
u8g2_DrawHXBM(u8g2, x, y, w, bitmap);
|
||||
bitmap += blen;
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void u8g2_DrawHXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t color = u8g2->draw_color;
|
||||
uint8_t ncolor = (color == 0 ? 1 : 0);
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
mask = 1;
|
||||
while(len > 0)
|
||||
{
|
||||
if( u8x8_pgm_read(b) & mask ) {
|
||||
u8g2->draw_color = color;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
} else if( u8g2->bitmap_transparency == 0 ) {
|
||||
u8g2->draw_color = ncolor;
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
x++;
|
||||
mask <<= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 1;
|
||||
b++;
|
||||
}
|
||||
len--;
|
||||
}
|
||||
u8g2->draw_color = color;
|
||||
}
|
||||
|
||||
|
||||
void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
|
||||
{
|
||||
u8g2_uint_t blen;
|
||||
blen = w;
|
||||
blen += 7;
|
||||
blen >>= 3;
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
while( h > 0 )
|
||||
{
|
||||
u8g2_DrawHXBMP(u8g2, x, y, w, bitmap);
|
||||
bitmap += blen;
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
210
Middlewares/u8g2Lib/src/u8g2_box.c
Normal file
210
Middlewares/u8g2Lib/src/u8g2_box.c
Normal file
@ -0,0 +1,210 @@
|
||||
/*
|
||||
|
||||
u8g2_box.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/*
|
||||
draw a filled box
|
||||
restriction: does not work for w = 0 or h = 0
|
||||
*/
|
||||
void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
while( h != 0 )
|
||||
{
|
||||
u8g2_DrawHVLine(u8g2, x, y, w, 0);
|
||||
y++;
|
||||
h--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
draw a frame (empty box)
|
||||
restriction: does not work for w = 0 or h = 0
|
||||
*/
|
||||
void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
|
||||
{
|
||||
u8g2_uint_t xtmp = x;
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
u8g2_DrawHVLine(u8g2, x, y, w, 0);
|
||||
if (h >= 2) {
|
||||
h-=2;
|
||||
y++;
|
||||
if (h > 0) {
|
||||
u8g2_DrawHVLine(u8g2, x, y, h, 1);
|
||||
x+=w;
|
||||
x--;
|
||||
u8g2_DrawHVLine(u8g2, x, y, h, 1);
|
||||
y+=h;
|
||||
}
|
||||
u8g2_DrawHVLine(u8g2, xtmp, y, w, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void u8g2_DrawRBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
|
||||
{
|
||||
u8g2_uint_t xl, yu;
|
||||
u8g2_uint_t yl, xr;
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
xl = x;
|
||||
xl += r;
|
||||
yu = y;
|
||||
yu += r;
|
||||
|
||||
xr = x;
|
||||
xr += w;
|
||||
xr -= r;
|
||||
xr -= 1;
|
||||
|
||||
yl = y;
|
||||
yl += h;
|
||||
yl -= r;
|
||||
yl -= 1;
|
||||
|
||||
u8g2_DrawDisc(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
|
||||
u8g2_DrawDisc(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
|
||||
u8g2_DrawDisc(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
|
||||
u8g2_DrawDisc(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
|
||||
|
||||
{
|
||||
u8g2_uint_t ww, hh;
|
||||
|
||||
ww = w;
|
||||
ww -= r;
|
||||
ww -= r;
|
||||
xl++;
|
||||
yu++;
|
||||
|
||||
if ( ww >= 3 )
|
||||
{
|
||||
ww -= 2;
|
||||
u8g2_DrawBox(u8g2, xl, y, ww, r+1);
|
||||
u8g2_DrawBox(u8g2, xl, yl, ww, r+1);
|
||||
}
|
||||
|
||||
hh = h;
|
||||
hh -= r;
|
||||
hh -= r;
|
||||
//h--;
|
||||
if ( hh >= 3 )
|
||||
{
|
||||
hh -= 2;
|
||||
u8g2_DrawBox(u8g2, x, yu, w, hh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void u8g2_DrawRFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
|
||||
{
|
||||
u8g2_uint_t xl, yu;
|
||||
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
xl = x;
|
||||
xl += r;
|
||||
yu = y;
|
||||
yu += r;
|
||||
|
||||
{
|
||||
u8g2_uint_t yl, xr;
|
||||
|
||||
xr = x;
|
||||
xr += w;
|
||||
xr -= r;
|
||||
xr -= 1;
|
||||
|
||||
yl = y;
|
||||
yl += h;
|
||||
yl -= r;
|
||||
yl -= 1;
|
||||
|
||||
u8g2_DrawCircle(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
|
||||
u8g2_DrawCircle(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
|
||||
u8g2_DrawCircle(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
|
||||
u8g2_DrawCircle(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
|
||||
}
|
||||
|
||||
{
|
||||
u8g2_uint_t ww, hh;
|
||||
|
||||
ww = w;
|
||||
ww -= r;
|
||||
ww -= r;
|
||||
hh = h;
|
||||
hh -= r;
|
||||
hh -= r;
|
||||
|
||||
xl++;
|
||||
yu++;
|
||||
|
||||
if ( ww >= 3 )
|
||||
{
|
||||
ww -= 2;
|
||||
h--;
|
||||
u8g2_DrawHLine(u8g2, xl, y, ww);
|
||||
u8g2_DrawHLine(u8g2, xl, y+h, ww);
|
||||
}
|
||||
|
||||
if ( hh >= 3 )
|
||||
{
|
||||
hh -= 2;
|
||||
w--;
|
||||
u8g2_DrawVLine(u8g2, x, yu, hh);
|
||||
u8g2_DrawVLine(u8g2, x+w, yu, hh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
213
Middlewares/u8g2Lib/src/u8g2_buffer.c
Normal file
213
Middlewares/u8g2Lib/src/u8g2_buffer.c
Normal file
@ -0,0 +1,213 @@
|
||||
/*
|
||||
|
||||
u8g2_buffer.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <string.h>
|
||||
|
||||
/*============================================*/
|
||||
void u8g2_ClearBuffer(u8g2_t *u8g2)
|
||||
{
|
||||
size_t cnt;
|
||||
cnt = u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
cnt *= u8g2->tile_buf_height;
|
||||
cnt *= 8;
|
||||
memset(u8g2->tile_buf_ptr, 0, cnt);
|
||||
}
|
||||
|
||||
/*============================================*/
|
||||
|
||||
static void u8g2_send_tile_row(u8g2_t *u8g2, uint8_t src_tile_row, uint8_t dest_tile_row)
|
||||
{
|
||||
uint8_t *ptr;
|
||||
uint16_t offset;
|
||||
uint8_t w;
|
||||
|
||||
w = u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
offset = src_tile_row;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
offset *= w;
|
||||
offset *= 8;
|
||||
ptr += offset;
|
||||
u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0, dest_tile_row, w, ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
write the buffer to the display RAM.
|
||||
For most displays, this will make the content visible to the user.
|
||||
Some displays (like the SSD1606) require a u8x8_RefreshDisplay()
|
||||
*/
|
||||
static void u8g2_send_buffer(u8g2_t *u8g2) U8X8_NOINLINE;
|
||||
static void u8g2_send_buffer(u8g2_t *u8g2)
|
||||
{
|
||||
uint8_t src_row;
|
||||
uint8_t src_max;
|
||||
uint8_t dest_row;
|
||||
uint8_t dest_max;
|
||||
|
||||
src_row = 0;
|
||||
src_max = u8g2->tile_buf_height;
|
||||
dest_row = u8g2->tile_curr_row;
|
||||
dest_max = u8g2_GetU8x8(u8g2)->display_info->tile_height;
|
||||
|
||||
do
|
||||
{
|
||||
u8g2_send_tile_row(u8g2, src_row, dest_row);
|
||||
src_row++;
|
||||
dest_row++;
|
||||
} while( src_row < src_max && dest_row < dest_max );
|
||||
}
|
||||
|
||||
/* same as u8g2_send_buffer but also send the DISPLAY_REFRESH message (used by SSD1606) */
|
||||
void u8g2_SendBuffer(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_send_buffer(u8g2);
|
||||
u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
|
||||
}
|
||||
|
||||
/*============================================*/
|
||||
void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
|
||||
{
|
||||
u8g2->tile_curr_row = row;
|
||||
u8g2->cb->update_dimension(u8g2);
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_FirstPage(u8g2_t *u8g2)
|
||||
{
|
||||
if ( u8g2->is_auto_page_clear )
|
||||
{
|
||||
u8g2_ClearBuffer(u8g2);
|
||||
}
|
||||
u8g2_SetBufferCurrTileRow(u8g2, 0);
|
||||
}
|
||||
|
||||
uint8_t u8g2_NextPage(u8g2_t *u8g2)
|
||||
{
|
||||
uint8_t row;
|
||||
u8g2_send_buffer(u8g2);
|
||||
row = u8g2->tile_curr_row;
|
||||
row += u8g2->tile_buf_height;
|
||||
if ( row >= u8g2_GetU8x8(u8g2)->display_info->tile_height )
|
||||
{
|
||||
u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
|
||||
return 0;
|
||||
}
|
||||
if ( u8g2->is_auto_page_clear )
|
||||
{
|
||||
u8g2_ClearBuffer(u8g2);
|
||||
}
|
||||
u8g2_SetBufferCurrTileRow(u8g2, row);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================*/
|
||||
/*
|
||||
Description:
|
||||
Update a sub area of the display, given by tile position, width and height.
|
||||
The arguments are "tile" coordinates. Any u8g2 rotation is ignored.
|
||||
This procedure only checks whether full buffer mode is active.
|
||||
There is no error checking for the arguments: It is the responsibility of the
|
||||
user to ensure, that the provided arguments are correct.
|
||||
|
||||
Limitations:
|
||||
- Only available in full buffer mode (will not do anything in page mode)
|
||||
- Tile positions and sizes (pixel position divided by 8)
|
||||
- Any display rotation/mirror is ignored
|
||||
- Only works with displays, which support U8x8 API
|
||||
- Will not send the e-paper refresh message (will probably not work with e-paper devices)
|
||||
*/
|
||||
void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th)
|
||||
{
|
||||
uint16_t page_size;
|
||||
uint8_t *ptr;
|
||||
|
||||
/* check, whether we are in full buffer mode */
|
||||
if ( u8g2->tile_buf_height != u8g2_GetU8x8(u8g2)->display_info->tile_height )
|
||||
return; /* not in full buffer mode, do nothing */
|
||||
|
||||
page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */
|
||||
|
||||
ptr = u8g2_GetBufferPtr(u8g2);
|
||||
ptr += tx*8;
|
||||
ptr += page_size*ty;
|
||||
|
||||
while( th > 0 )
|
||||
{
|
||||
u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw, ptr );
|
||||
ptr += page_size;
|
||||
ty++;
|
||||
th--;
|
||||
}
|
||||
}
|
||||
|
||||
/* same as sendBuffer, but does not send the ePaper refresh message */
|
||||
void u8g2_UpdateDisplay(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_send_buffer(u8g2);
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
|
||||
/* vertical_top memory architecture */
|
||||
void u8g2_WriteBufferPBM(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
|
||||
}
|
||||
|
||||
void u8g2_WriteBufferXBM(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
|
||||
}
|
||||
|
||||
|
||||
/* horizontal right memory architecture */
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
void u8g2_WriteBufferPBM2(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
|
||||
}
|
||||
|
||||
void u8g2_WriteBufferXBM2(u8g2_t *u8g2, void (*out)(const char *s))
|
||||
{
|
||||
u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
|
||||
u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
|
||||
}
|
||||
|
||||
313
Middlewares/u8g2Lib/src/u8g2_button.c
Normal file
313
Middlewares/u8g2Lib/src/u8g2_button.c
Normal file
@ -0,0 +1,313 @@
|
||||
/*
|
||||
|
||||
u8g2_button.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Description:
|
||||
Draws normal or inverted text with optional frame around text.
|
||||
The text (and the frame) can be horizontally centered around the provided reference position.
|
||||
This procedure will use the current draw color and current font. The height of the frame
|
||||
depends on the setting of setFontRefHeightText(), setFontRefHeightExtendedText() or setFontRefHeightAll()
|
||||
|
||||
|
||||
Note 1: drawColor 2 (XOR) is not supported. Result will be broken with draw color 2.
|
||||
Note 2: This procedure will enforce font mode 1 (transparent mode)
|
||||
Note 3: Some fonts may add an extra gap on the right side. This is a font problem and can not be avoided (for example inb16 has this problem).
|
||||
|
||||
|
||||
The height of the button is defined by the current font and
|
||||
setFontRefHeightText,
|
||||
setFontRefHeightExtendedText
|
||||
setFontRefHeightAll
|
||||
Right padding might be influenced by the font.
|
||||
For example u8g2_font_inb16 may add an extra pixel gap (increase padding by one)
|
||||
on the right side.
|
||||
The current draw color is considered, but only draw color 0 and 1 are supported
|
||||
|
||||
This function requires transparent font mode: setFontMode(1)
|
||||
|
||||
Side effect: Font transparent mode is enabled setFontMode(1)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
flags:
|
||||
|
||||
U8G2_BTN_BW1 0x01
|
||||
U8G2_BTN_BW2 0x02
|
||||
U8G2_BTN_BW3 0x03
|
||||
|
||||
|
||||
U8G2_BTN_SHADOW0 0x08
|
||||
U8G2_BTN_SHADOW1 0x10
|
||||
U8G2_BTN_SHADOW2 0x18
|
||||
|
||||
U8G2_BTN_INV 0x20
|
||||
|
||||
U8G2_BTN_HCENTER 0x40
|
||||
|
||||
U8G2_BTN_XFRAME 0x80
|
||||
|
||||
Total size without shadow: width+2*padding_h+2*border
|
||||
Total size with U8G2_BTN_SHADOW0: width+2*padding_h+3*border
|
||||
Total size with U8G2_BTN_SHADOW1: width+2*padding_h+3*border+1
|
||||
Total size with U8G2_BTN_SHADOW2: width+2*padding_h+3*border+2
|
||||
|
||||
U8G2_BTN_XFRAME:
|
||||
draw another one pixel frame with one pixel gap, will not look good with shadow
|
||||
*/
|
||||
|
||||
void u8g2_DrawButtonFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t flags, u8g2_uint_t text_width, u8g2_uint_t padding_h, u8g2_uint_t padding_v)
|
||||
{
|
||||
u8g2_uint_t w = text_width;
|
||||
|
||||
u8g2_uint_t xx, yy, ww, hh;
|
||||
|
||||
u8g2_uint_t gap_frame = U8G2_BTN_BW_MASK+1;
|
||||
|
||||
u8g2_uint_t border_width = flags & U8G2_BTN_BW_MASK;
|
||||
|
||||
int8_t a = u8g2_GetAscent(u8g2);
|
||||
int8_t d = u8g2_GetDescent(u8g2);
|
||||
|
||||
uint8_t color_backup = u8g2->draw_color;
|
||||
|
||||
|
||||
if ( flags & U8G2_BTN_XFRAME )
|
||||
{
|
||||
border_width++;
|
||||
gap_frame = border_width;
|
||||
border_width++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
|
||||
xx = x;
|
||||
xx -= padding_h;
|
||||
xx -= border_width;
|
||||
ww = w+2*padding_h+2*border_width;
|
||||
|
||||
yy = y;
|
||||
yy += u8g2->font_calc_vref(u8g2);
|
||||
yy -= a;
|
||||
yy -= padding_v;
|
||||
yy -= border_width;
|
||||
hh = a-d+2*padding_v+2*border_width;
|
||||
if ( border_width == 0 )
|
||||
break;
|
||||
if ( border_width == gap_frame )
|
||||
{
|
||||
u8g2_SetDrawColor(u8g2, color_backup == 0 ? 1 : 0);
|
||||
}
|
||||
u8g2_DrawFrame(u8g2, xx, yy, ww, hh);
|
||||
u8g2_SetDrawColor(u8g2, color_backup);
|
||||
|
||||
if ( flags & U8G2_BTN_SHADOW_MASK )
|
||||
{
|
||||
if ( border_width == (flags & U8G2_BTN_BW_MASK) )
|
||||
{
|
||||
u8g2_uint_t i;
|
||||
u8g2_uint_t shadow_gap = (flags & U8G2_BTN_SHADOW_MASK) >> U8G2_BTN_SHADOW_POS;
|
||||
shadow_gap--;
|
||||
for( i = 0; i < border_width; i++ )
|
||||
{
|
||||
u8g2_DrawHLine(u8g2, xx+border_width+shadow_gap,yy+hh+i+shadow_gap,ww);
|
||||
u8g2_DrawVLine(u8g2, xx+ww+i+shadow_gap,yy+border_width+shadow_gap,hh);
|
||||
}
|
||||
}
|
||||
}
|
||||
border_width--;
|
||||
} /* for */
|
||||
|
||||
if ( flags & U8G2_BTN_INV )
|
||||
{
|
||||
u8g2_SetDrawColor(u8g2, 2); /* XOR */
|
||||
u8g2_DrawBox(u8g2, xx, yy, ww, hh);
|
||||
u8g2_SetDrawColor(u8g2, color_backup);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawButtonUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t flags, u8g2_uint_t width, u8g2_uint_t padding_h, u8g2_uint_t padding_v, const char *text)
|
||||
{
|
||||
u8g2_uint_t w = u8g2_GetUTF8Width(u8g2, text);
|
||||
|
||||
u8g2_uint_t text_x_offset = 0;
|
||||
|
||||
if ( flags & U8G2_BTN_HCENTER )
|
||||
x -= (w+1)/2;
|
||||
|
||||
if ( w < width )
|
||||
{
|
||||
if ( flags & U8G2_BTN_HCENTER )
|
||||
{
|
||||
text_x_offset = (width-w)/2;
|
||||
}
|
||||
w = width;
|
||||
}
|
||||
|
||||
u8g2_SetFontMode(u8g2, 1);
|
||||
u8g2_DrawUTF8(u8g2, x,y, text);
|
||||
u8g2_DrawButtonFrame(u8g2, x-text_x_offset, y, flags, w, padding_h, padding_v);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef NOT_USED
|
||||
void u8g2_Draw4Pixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w)
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x,y-1);
|
||||
u8g2_DrawPixel(u8g2, x+w-1,y-1);
|
||||
u8g2_DrawPixel(u8g2, x+w-1,y-w);
|
||||
u8g2_DrawPixel(u8g2, x,y-w);
|
||||
}
|
||||
|
||||
void u8g2_DrawRadio(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t is_checked)
|
||||
{
|
||||
uint8_t color_backup = u8g2->draw_color;
|
||||
u8g2_DrawCheckbox(u8g2, x,y,w,is_checked);
|
||||
u8g2_SetDrawColor(u8g2, 2);
|
||||
u8g2_Draw4Pixel(u8g2, x,y,w);
|
||||
if ( is_checked )
|
||||
{
|
||||
//u8g2_Draw4Pixel(u8g2, x+2,y-2,w-4);
|
||||
}
|
||||
|
||||
u8g2_SetDrawColor(u8g2, color_backup );
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _THIS_CODE_SHOULD_BE_REWRITTEN_WITHOUT_PADWIDTH_
|
||||
|
||||
/*
|
||||
Shadow is not supported
|
||||
Note: radius must be at least as high as the border width
|
||||
|
||||
border width | good radius values
|
||||
1 | 3, 5, 7, 8, ...
|
||||
2 | 3, 5, 7, 8, ...
|
||||
|
||||
*/
|
||||
|
||||
void u8g2_DrawRButtonUTF8(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t flags, u8g2_uint_t padding_h_or_width, u8g2_uint_t padding_v, u8g2_uint_t r, const char *text)
|
||||
{
|
||||
u8g2_uint_t w = u8g2_GetUTF8Width(u8g2, text);
|
||||
//u8g2_uint_t w = u8g2_GetExactStrWidth(u8g2, text);
|
||||
|
||||
u8g2_uint_t xx, yy, ww, hh;
|
||||
|
||||
u8g2_uint_t border_width = flags & U8G2_BTN_BW_MASK;
|
||||
u8g2_uint_t padding_h = padding_h_or_width;
|
||||
u8g2_uint_t text_x_offset = 0; // used for U8G2_BTN_PADWIDTH mode
|
||||
|
||||
int8_t a = u8g2_GetAscent(u8g2);
|
||||
int8_t d = u8g2_GetDescent(u8g2);
|
||||
uint8_t color_backup = u8g2->draw_color;
|
||||
|
||||
|
||||
if ( flags & U8G2_BTN_HCENTER )
|
||||
x -= w/2;
|
||||
|
||||
if ( flags & U8G2_BTN_PADWIDTH )
|
||||
{
|
||||
padding_h = 0;
|
||||
if ( w < padding_h_or_width )
|
||||
{
|
||||
if ( flags & U8G2_BTN_HCENTER )
|
||||
{
|
||||
text_x_offset = (padding_h_or_width-w)/2;
|
||||
}
|
||||
w = padding_h_or_width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
u8g2_SetFontMode(u8g2, 1);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
if ( padding_h >= u8g2_GetDisplayWidth(u8g2)/2 ) // padding_h is zero if U8G2_BTN_PADWIDTH is set
|
||||
{
|
||||
xx = (flags & U8G2_BTN_BW_MASK) - border_width;
|
||||
ww = u8g2_GetDisplayWidth(u8g2);
|
||||
ww -= 2*((flags & U8G2_BTN_BW_MASK) - border_width);
|
||||
//printf("xx=%d ww=%d\n", xx, ww);
|
||||
//printf("clip_x1=%d clip_x0=%d\n", u8g2->clip_x1, u8g2->clip_x0);
|
||||
}
|
||||
else
|
||||
{
|
||||
xx = x;
|
||||
xx -= text_x_offset;
|
||||
xx -= padding_h;
|
||||
xx -= border_width;
|
||||
ww = w+2*padding_h+2*border_width;
|
||||
}
|
||||
|
||||
yy = y;
|
||||
yy += u8g2->font_calc_vref(u8g2);
|
||||
yy -= a;
|
||||
yy -= padding_v;
|
||||
yy -= border_width;
|
||||
hh = a-d+2*padding_v+2*border_width;
|
||||
if ( border_width == 0 )
|
||||
break;
|
||||
u8g2_DrawRFrame(u8g2, xx, yy, ww, hh, r);
|
||||
if ( (flags & U8G2_BTN_BW_MASK) > 1 )
|
||||
u8g2_DrawRFrame(u8g2, xx, yy, ww, hh, r+1);
|
||||
|
||||
border_width--;
|
||||
if ( r > 1 )
|
||||
r--;
|
||||
}
|
||||
if ( flags & U8G2_BTN_INV )
|
||||
{
|
||||
u8g2_DrawRBox(u8g2, xx, yy, ww, hh,r);
|
||||
u8g2_SetDrawColor(u8g2, 1-u8g2->draw_color);
|
||||
}
|
||||
u8g2_DrawUTF8(u8g2, x,y, text);
|
||||
u8g2_SetDrawColor(u8g2, color_backup);
|
||||
}
|
||||
|
||||
#endif
|
||||
479
Middlewares/u8g2Lib/src/u8g2_circle.c
Normal file
479
Middlewares/u8g2Lib/src/u8g2_circle.c
Normal file
@ -0,0 +1,479 @@
|
||||
/*
|
||||
|
||||
u8g2_circle.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/*==============================================*/
|
||||
/* Circle */
|
||||
|
||||
static void u8g2_draw_circle_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
|
||||
static void u8g2_draw_circle_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 - y);
|
||||
u8g2_DrawPixel(u8g2, x0 + y, y0 - x);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 - y);
|
||||
u8g2_DrawPixel(u8g2, x0 - y, y0 - x);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 + y);
|
||||
u8g2_DrawPixel(u8g2, x0 + y, y0 + x);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 + y);
|
||||
u8g2_DrawPixel(u8g2, x0 - y, y0 + x);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_circle(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g2_int_t f;
|
||||
u8g2_int_t ddF_x;
|
||||
u8g2_int_t ddF_y;
|
||||
u8g2_uint_t x;
|
||||
u8g2_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g2_draw_circle_section(u8g2, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g2_draw_circle_section(u8g2, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawCircle(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rad, y0-rad, x0+rad+1, y0+rad+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
|
||||
/* draw circle */
|
||||
u8g2_draw_circle(u8g2, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
/*==============================================*/
|
||||
/* Disk */
|
||||
|
||||
static void u8g2_draw_disc_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
|
||||
static void u8g2_draw_disc_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0-y, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0+y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0-y, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0-y, y0-x, x+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0+y, y0, x+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0, y+1);
|
||||
u8g2_DrawVLine(u8g2, x0-y, y0, x+1);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_disc(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
u8g2_int_t f;
|
||||
u8g2_int_t ddF_x;
|
||||
u8g2_int_t ddF_y;
|
||||
u8g2_uint_t x;
|
||||
u8g2_uint_t y;
|
||||
|
||||
f = 1;
|
||||
f -= rad;
|
||||
ddF_x = 1;
|
||||
ddF_y = 0;
|
||||
ddF_y -= rad;
|
||||
ddF_y *= 2;
|
||||
x = 0;
|
||||
y = rad;
|
||||
|
||||
u8g2_draw_disc_section(u8g2, x, y, x0, y0, option);
|
||||
|
||||
while ( x < y )
|
||||
{
|
||||
if (f >= 0)
|
||||
{
|
||||
y--;
|
||||
ddF_y += 2;
|
||||
f += ddF_y;
|
||||
}
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
|
||||
u8g2_draw_disc_section(u8g2, x, y, x0, y0, option);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawDisc(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rad, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rad, y0-rad, x0+rad+1, y0+rad+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
/* draw disc */
|
||||
u8g2_draw_disc(u8g2, x0, y0, rad, option);
|
||||
}
|
||||
|
||||
/*==============================================*/
|
||||
/* Ellipse */
|
||||
|
||||
/*
|
||||
Source:
|
||||
Foley, Computer Graphics, p 90
|
||||
*/
|
||||
static void u8g2_draw_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
static void u8g2_draw_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 - y);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 - y);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 + x, y0 + y);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawPixel(u8g2, x0 - x, y0 + y);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_ellipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
u8g2_uint_t x, y;
|
||||
u8g2_long_t xchg, ychg;
|
||||
u8g2_long_t err;
|
||||
u8g2_long_t rxrx2;
|
||||
u8g2_long_t ryry2;
|
||||
u8g2_long_t stopx, stopy;
|
||||
|
||||
rxrx2 = rx;
|
||||
rxrx2 *= rx;
|
||||
rxrx2 *= 2;
|
||||
|
||||
ryry2 = ry;
|
||||
ryry2 *= ry;
|
||||
ryry2 *= 2;
|
||||
|
||||
x = rx;
|
||||
y = 0;
|
||||
|
||||
xchg = 1;
|
||||
xchg -= rx;
|
||||
xchg -= rx;
|
||||
xchg *= ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = ryry2;
|
||||
stopx *= rx;
|
||||
stopy = 0;
|
||||
|
||||
while( stopx >= stopy )
|
||||
{
|
||||
u8g2_draw_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
y++;
|
||||
stopy += rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
if ( 2*err+xchg > 0 )
|
||||
{
|
||||
x--;
|
||||
stopx -= ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = ry;
|
||||
|
||||
xchg = ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = 1;
|
||||
ychg -= ry;
|
||||
ychg -= ry;
|
||||
ychg *= rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = 0;
|
||||
|
||||
stopy = rxrx2;
|
||||
stopy *= ry;
|
||||
|
||||
|
||||
while( stopx <= stopy )
|
||||
{
|
||||
u8g2_draw_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
x++;
|
||||
stopx += ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
if ( 2*err+ychg > 0 )
|
||||
{
|
||||
y--;
|
||||
stopy -= rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8g2_DrawEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rx, y0-ry, x0+rx+1, y0+ry+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
u8g2_draw_ellipse(u8g2, x0, y0, rx, ry, option);
|
||||
}
|
||||
|
||||
/*==============================================*/
|
||||
/* Filled Ellipse */
|
||||
|
||||
static void u8g2_draw_filled_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option) U8G2_NOINLINE;
|
||||
static void u8g2_draw_filled_ellipse_section(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t x0, u8g2_uint_t y0, uint8_t option)
|
||||
{
|
||||
/* upper right */
|
||||
if ( option & U8G2_DRAW_UPPER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0-y, y+1);
|
||||
}
|
||||
|
||||
/* upper left */
|
||||
if ( option & U8G2_DRAW_UPPER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0-y, y+1);
|
||||
}
|
||||
|
||||
/* lower right */
|
||||
if ( option & U8G2_DRAW_LOWER_RIGHT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0+x, y0, y+1);
|
||||
}
|
||||
|
||||
/* lower left */
|
||||
if ( option & U8G2_DRAW_LOWER_LEFT )
|
||||
{
|
||||
u8g2_DrawVLine(u8g2, x0-x, y0, y+1);
|
||||
}
|
||||
}
|
||||
|
||||
static void u8g2_draw_filled_ellipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
u8g2_uint_t x, y;
|
||||
u8g2_long_t xchg, ychg;
|
||||
u8g2_long_t err;
|
||||
u8g2_long_t rxrx2;
|
||||
u8g2_long_t ryry2;
|
||||
u8g2_long_t stopx, stopy;
|
||||
|
||||
rxrx2 = rx;
|
||||
rxrx2 *= rx;
|
||||
rxrx2 *= 2;
|
||||
|
||||
ryry2 = ry;
|
||||
ryry2 *= ry;
|
||||
ryry2 *= 2;
|
||||
|
||||
x = rx;
|
||||
y = 0;
|
||||
|
||||
xchg = 1;
|
||||
xchg -= rx;
|
||||
xchg -= rx;
|
||||
xchg *= ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = ryry2;
|
||||
stopx *= rx;
|
||||
stopy = 0;
|
||||
|
||||
while( stopx >= stopy )
|
||||
{
|
||||
u8g2_draw_filled_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
y++;
|
||||
stopy += rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
if ( 2*err+xchg > 0 )
|
||||
{
|
||||
x--;
|
||||
stopx -= ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
}
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = ry;
|
||||
|
||||
xchg = ry;
|
||||
xchg *= ry;
|
||||
|
||||
ychg = 1;
|
||||
ychg -= ry;
|
||||
ychg -= ry;
|
||||
ychg *= rx;
|
||||
ychg *= rx;
|
||||
|
||||
err = 0;
|
||||
|
||||
stopx = 0;
|
||||
|
||||
stopy = rxrx2;
|
||||
stopy *= ry;
|
||||
|
||||
|
||||
while( stopx <= stopy )
|
||||
{
|
||||
u8g2_draw_filled_ellipse_section(u8g2, x, y, x0, y0, option);
|
||||
x++;
|
||||
stopx += ryry2;
|
||||
err += xchg;
|
||||
xchg += ryry2;
|
||||
if ( 2*err+ychg > 0 )
|
||||
{
|
||||
y--;
|
||||
stopy -= rxrx2;
|
||||
err += ychg;
|
||||
ychg += rxrx2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8g2_DrawFilledEllipse(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t rx, u8g2_uint_t ry, uint8_t option)
|
||||
{
|
||||
/* check for bounding box */
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
{
|
||||
if ( u8g2_IsIntersection(u8g2, x0-rx, y0-ry, x0+rx+1, y0+ry+1) == 0 )
|
||||
return;
|
||||
}
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
u8g2_draw_filled_ellipse(u8g2, x0, y0, rx, ry, option);
|
||||
}
|
||||
|
||||
|
||||
54
Middlewares/u8g2Lib/src/u8g2_cleardisplay.c
Normal file
54
Middlewares/u8g2Lib/src/u8g2_cleardisplay.c
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
|
||||
u8g2_cleardisplay.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
#include "u8g2.h"
|
||||
|
||||
/* Clear screen buffer & display reliable for all u8g2 displays. */
|
||||
/* This is done with u8g2 picture loop, because we can not use the u8x8 function in all cases */
|
||||
void u8g2_ClearDisplay(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_FirstPage(u8g2);
|
||||
do {
|
||||
} while ( u8g2_NextPage(u8g2) );
|
||||
/*
|
||||
This function is usually called during startup (u8g2.begin()).
|
||||
However the user might want to use full buffer mode with clear and
|
||||
send commands.
|
||||
This will not work because the current tile row is modified by the picture
|
||||
loop above. To fix this, reset the tile row to 0, issue #370
|
||||
A workaround would be, that the user sets the current tile row to 0 manually.
|
||||
*/
|
||||
u8g2_SetBufferCurrTileRow(u8g2, 0);
|
||||
}
|
||||
|
||||
18
Middlewares/u8g2Lib/src/u8g2_d_memory.c
Normal file
18
Middlewares/u8g2Lib/src/u8g2_d_memory.c
Normal file
@ -0,0 +1,18 @@
|
||||
/* u8g2_d_memory.c */
|
||||
/* generated code, codebuild, u8g2 project */
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
|
||||
uint8_t *u8g2_m_16_8_f(uint8_t *page_cnt)
|
||||
{
|
||||
#ifdef U8G2_USE_DYNAMIC_ALLOC
|
||||
*page_cnt = 8;
|
||||
return 0;
|
||||
#else
|
||||
static uint8_t buf[1024];
|
||||
*page_cnt = 8;
|
||||
return buf;
|
||||
#endif
|
||||
}
|
||||
/* end of generated code */
|
||||
14
Middlewares/u8g2Lib/src/u8g2_d_setup.c
Normal file
14
Middlewares/u8g2Lib/src/u8g2_d_setup.c
Normal file
@ -0,0 +1,14 @@
|
||||
/* u8g2_d_setup.c */
|
||||
/* generated code, codebuild, u8g2 project */
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/* ssd1306 f */
|
||||
void u8g2_Setup_ssd1306_i2c_128x64_noname_f(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
|
||||
{
|
||||
uint8_t tile_buf_height;
|
||||
uint8_t *buf;
|
||||
u8g2_SetupDisplay(u8g2, u8x8_d_ssd1306_128x64_noname, u8x8_cad_ssd13xx_fast_i2c, byte_cb, gpio_and_delay_cb);
|
||||
buf = u8g2_m_16_8_f(&tile_buf_height);
|
||||
u8g2_SetupBuffer(u8g2, buf, tile_buf_height, u8g2_ll_hvline_vertical_top_lsb, rotation);
|
||||
}
|
||||
1541
Middlewares/u8g2Lib/src/u8g2_font.c
Normal file
1541
Middlewares/u8g2Lib/src/u8g2_font.c
Normal file
File diff suppressed because it is too large
Load Diff
97
Middlewares/u8g2Lib/src/u8g2_fonts.c
Normal file
97
Middlewares/u8g2Lib/src/u8g2_fonts.c
Normal file
@ -0,0 +1,97 @@
|
||||
/*
|
||||
u8g2_fonts.c
|
||||
*/
|
||||
#include "u8g2.h"
|
||||
|
||||
const uint8_t u8g2_font_profont12_mf[2911] U8G2_FONT_SECTION("u8g2_font_profont12_mf") =
|
||||
"\340\2\3\2\3\4\1\2\4\6\14\0\376\10\376\11\377\1\202\3>\13B \7\346\370\371O\0!\12"
|
||||
"\346\370\361\264w\60\247\0\42\13\346\370\223,\311\222\234_\0#\16\346\370\341$\32\244$\32\244$\347"
|
||||
"\10$\17\346\370\221pJ:\216I\226t\32s\10%\16\346\370\341!\351S\22jJO\71\1&\17"
|
||||
"\346\370a-\252\204\225,i\312\224\34\6'\11\346\370\221\264\316O\0(\12\346\370\241\260\332s\35\1"
|
||||
")\11\346\370\343j\217u\14*\14\346\370\361,)MI-\347\12+\12\346\370Yk\203\226\346\14,"
|
||||
"\11\346\370\371.\252a\10-\10\346\370y\332\71\2.\10\346\370\371E\324\11/\15\346\370Ii\230\206"
|
||||
"i\230\206i\12\60\20\346\370\341)K\42\245EJ\262$\213v\2\61\13\346\370\361l\355m\320a\0"
|
||||
"\62\14\346\370\341)K\303\256\203\16\3\63\15\346\370\341)K\63\71M\262h'\64\16\346\370)\241\226"
|
||||
"D\245AL\303\35\6\65\16\346\370\321AI\323!N\223,\332\11\66\17\346\370\341)M\207(K\262"
|
||||
"$\213v\2\67\13\346\370\321A-V\333)\0\70\20\346\370\341)K\262h\312\222,\311\242\235\0\71"
|
||||
"\16\346\370\341)K\262$\213\206\264\264\23:\12\346\370YE\235$\352\4;\13\346\370\31\355$Q\15"
|
||||
"C\0<\11\346\370Ias;\25=\12\346\370\331\6}\320\271\1>\11\346\370\341\216\355,\0\77\14"
|
||||
"\346\370\341)K\213u\60\247\0@\17\346\370\341)K\222\245\313\222\306C\16\3A\22\346\370\361\60\311"
|
||||
"\222(K\262dP\262$\313a\0B\22\346\370\321!\312\222,\31\242,\311\222,\31r\2C\13\346"
|
||||
"\370\341)K\322n\321ND\22\346\370\321!\312\222,\311\222,\311\222,\31r\2E\16\346\370\321A"
|
||||
"I\323!J\253\203\16\3F\15\346\370\321AI\323!J\333i\0G\16\346\370\341)K\322\222\222%"
|
||||
"Y\264\23H\22\346\370\321,\311\222,\31\224,\311\222,\311r\30I\13\346\370\321AK{\33t\30"
|
||||
"J\14\346\370Ii\227,\311\242\235\0K\20\346\370\321,\211*\231(&YT\313a\0L\11\346\370"
|
||||
"\321~\35t\30M\20\346\370\321,\261\364[\222%Y\222\345\60\0N\21\346\370\321,\221\222NJ\226"
|
||||
"dI\226d\71\14O\20\346\370\341)K\262$K\262$K\262h'P\16\346\370\321!\312\222,\31"
|
||||
"\242\264\235\6Q\20\346\370\341)K\262$K\262$K\232\346\34R\22\346\370\321!\312\222,\31\242,"
|
||||
"\311\222,\311r\30S\15\346\370\341)K\342\71M\262h'T\12\346\370\321AK\373N\1U\21\346"
|
||||
"\370\321,\311\222,\311\222,\311\222,\332\11V\21\346\370\321,\311\222,\311\242$K\302\64\247\0W"
|
||||
"\20\346\370\321,\311\222,\311\222\276X\262\34\6X\21\346\370\321,\311\222,J\302J\224%Y\16\3"
|
||||
"Y\20\346\370\321,\311\222,\311\242$L\353\24\0Z\14\346\370\321A\15\273\246\203\16\3[\12\346\370"
|
||||
"\21\61\355W\35\1\134\14\346\370\341\64N\343\64N\343\64]\11\346\370\325\376\250C\0^\13\346\370\361"
|
||||
"\60\211\262\234/\0_\7\346\370\371\267a`\10\346\370\343\234\277\0a\16\346\370\271\15I\226dId"
|
||||
"\311a\0b\16\346\370\321\326!\312\222,\311\222!'c\14\346\370\271MY\222\306C\16\3d\20\346"
|
||||
"\370IiiH\262$K\262h\310a\0e\15\346\370\271MY\62(\361\220\303\0f\13\346\370)Z"
|
||||
"\70\246\335)\0g\17\346\370\271\15I\226dI\26\15i\64\1h\17\346\370\321\326!\312\222,\311\222"
|
||||
",\207\1i\12\346\370\361\234\244\66\356\4j\12\346\370\361\234\244\366&\2k\14\346\370\321N\225l\213"
|
||||
"j\71\14l\11\346\370a\265\217;\1m\13\346\370\71\15Q\322\377\16\3n\16\346\370\71%\222\224d"
|
||||
"I\226d\71\14o\14\346\370\271MY\222%Y\264\23p\17\346\370\71\15Q\226dI\226\14Q\232\2"
|
||||
"q\16\346\370\271\15I\226dI\26\15i\5r\14\346\370\71%\222\224\244u\32\0s\13\346\370\271\15"
|
||||
"I<'CNt\13\346\370\361\264\70\246e\35\6u\16\346\370\71eI\226dId\311a\0v\16"
|
||||
"\346\370\71eI\26%Y\22\346\24\0w\12\346\370\71%\375OINx\15\346\370\71eQ\22V\242"
|
||||
",\207\1y\17\346\370\71eI\226dI\26\15i\64\1z\13\346\370\71\15b\343\240\303\0{\13\346"
|
||||
"\370\241\60m\214\323\346\10|\11\346\370\221\264\177\207\0}\13\346\370\343\264\71L\33C\0~\12\346\370"
|
||||
"\31\225\212\316\33\0\177\7\346\370\371O\0\200\7\346\370\371O\0\201\7\346\370\371O\0\202\11\346\370\371"
|
||||
"\236\206\71\10\203\13\346\370\264\264qL\273\211\0\204\14\346\370\371\236dI\224\344\20\0\205\11\346\370\371"
|
||||
"\65\251\303\0\206\12\346\370\361pL\333\231\1\207\13\346\370\361pL\303\61g\6\210\11\346\370\221\60\311"
|
||||
"\371\3\211\21\346\370\207%RJI\30*\211\322S\222\303\0\212\16\346x\212\341\224%\361\234&Y\264"
|
||||
"\23\213\12\346\370y\12\323\70'\1\214\22\346\370\341!\251%Y\42%Y\222%\341\220\303\0\215\7\346"
|
||||
"\370\371O\0\216\7\346\370\371O\0\217\7\346\370\371O\0\220\7\346\370\371O\0\221\11\346\370)a\232"
|
||||
"\363\15\222\11\346\370)i\230\363\15\223\14\346\370\361$J\262$\347\23\0\224\14\346\370\361$K\242$"
|
||||
"\347\23\0\225\15\346\370\251\323\240\14\312 \355\254\0\226\10\346\370y\332\71\2\227\11\346\370y\31vN"
|
||||
"\0\230\10\346\370\225\212\316\37\231\13\346\370\321!\251,\311\316\7\232\15\346\370\223\60'\15I<'C"
|
||||
"N\233\12\346\370y\211\323\60\247\1\234\15\346\370\271%Q\322\262\24\23\35\6\235\7\346\370\371O\0\236"
|
||||
"\7\346\370\371O\0\237\17\346x\352x\226dI\26%aZ\247\0\240\7\346\370\371O\0\241\11\346\370"
|
||||
")\71\230\366N\242\16\346\370Y\303)\351\226\204C\226C\0\243\14\346\370\265\250\272\245m\311\220\23\244"
|
||||
"\14\346\370\331J[\222MYN\5\245\17\346\370\321,J\242A\313\6-\255S\0\246\13\346\370\221\264"
|
||||
"\235\226\266C\0\247\21\346x\246,\252\324\242ZTKJ\265hG\0\250\10\346\370\341$\347\17\251\17"
|
||||
"\346\370\321\71SjI\26)a\264S\0\252\13\346\270\246n;>\344\334\0\253\13\346\370y\252Dm"
|
||||
"Q\16\3\254\11\346\370\71\15j\235\21\255\11\346\370y\31tn\0\256\16\346\370\321\71\222\222\276HI"
|
||||
"\242\223\1\257\7\346\370\341\235\77\260\12\346\370\21-j\323\371\4\261\15\346\370\311i\66hi\66\350T"
|
||||
"\0\262\11\346x\344\60\334\371\5\263\12\346x\344P\315t\276\1\264\10\346\370\241;\77\3\265\12\346\370"
|
||||
"\71\365\247\245\232\2\266\20\346\370\207\244\177\32\262$K\262$Kr\30\267\10\346\370\71\332\71\2\270\11"
|
||||
"\346\370\371y\310\246\11\271\11\346x\324\342\316/\0\272\14\346\270\264\250M\247\14\71\67\0\273\13\346\370"
|
||||
"y\211\262\250%\312\11\274\16\346\70\324\332\220\204MI\244\255\71\14\275\16\346\70\324\332\220\204-JX"
|
||||
"\334Q\0\276\20\346\70\344P\252$JXJ\42m\315a\0\277\13\346\370\361\34l\255E;\1\300\22"
|
||||
"\346x\342\64L\262$\312\222,\31\224,\311r\30\301\22\346\370\302\64L\262$\312\222,\31\224,\311"
|
||||
"r\30\302\22\346\270\302$\307\302$K\242,\31\224,\311r\30\303\23\346x\224\212X\311\222(K\262"
|
||||
"dP\262$\313a\0\304\23\346x\352X\230dI\224%Y\62(Y\222\345\60\0\305\23\346\270\302$"
|
||||
"\254dI\224%Y\62(Y\222\345\60\0\306\22\346\370\341!\251%\331\20%Y\222%Y\262\303\0\307"
|
||||
"\14\346\370\341)K\322n\321X\4\310\17\346x\342lP\322t\210\322\352\240\303\0\311\17\346\370\302l"
|
||||
"P\322t\210\322\352\240\303\0\312\20\346\270\302$\32\224\64\35\242\264:\350\60\0\313\17\346x\352\310\240"
|
||||
"\244\351\20\245\325A\207\1\314\14\346x\342l\320\322\336\6\35\6\315\14\346\370\302l\320\322\336\6\35\6"
|
||||
"\316\16\346\270\302$G\6-\355\66\350\60\0\317\14\346x\352\310\240\245\275\15:\14\320\22\346\370\341!"
|
||||
"\312\222l\210\222,\311\222,\31r\30\321\23\346x\224\212\224%R\322I\311\222,\311\222,\207\1\322"
|
||||
"\21\346x\342p\312\222,\311\222,\311\222,\332\11\323\21\346\370\302p\312\222,\311\222,\311\222,\332"
|
||||
"\11\324\21\346\270\302$\207\246,\311\222,\311\222,\332\11\325\22\346x\224\212\66eI\226dI\226d"
|
||||
"I\26\355\4\326\21\346x\352\320\224%Y\222%Y\222%Y\264\23\327\15\346\370\211Y\224\204\225(\313"
|
||||
"\31\1\330\20\346\370\341)K\42\245EJ\262$\213v\2\331\21\346x\342\254\222%Y\222%Y\222%"
|
||||
"Y\264\23\332\21\346\370\302\254\222%Y\222%Y\222%Y\264\23\333\22\346\270\302$G\262$K\262$"
|
||||
"K\262$\213v\2\334\22\346x\352H\226dI\226dI\226dI\26\355\4\335\20\346\370\302\254\222%"
|
||||
"Y\222EI\230\326)\0\336\20\346\370\321t\210\262$K\262d\210\322\234\6\337\22\346\370\21-J\262"
|
||||
"$\352\226dI\226$R\16\2\340\20\346\370\221\70\247\14I\226dId\311a\0\341\20\346\370\241\60"
|
||||
"'\15I\226dId\311a\0\342\20\346\370\221\60\311)C\222%Y\22Yr\30\343\20\346\370\225\212"
|
||||
"N\31\222,\311\222\310\222\303\0\344\20\346\370\341$\247\14I\226dId\311a\0\345\21\346\370\221\60"
|
||||
"\11slH\262$K\42K\16\3\346\14\346\370\271MI\313R\34r\30\347\15\346\370\271MY\222\306"
|
||||
"C\26\206\0\350\16\346\370\343\234\64e\311\240\304C\16\3\351\17\346\370\241\60'MY\62(\361\220\303"
|
||||
"\0\352\20\346\370\221\60\311)S\226\14J<\344\60\0\353\17\346\370\341$\247LY\62(\361\220\303\0"
|
||||
"\354\12\346\370\343\234\244\66\356\4\355\13\346\370\241\60'\251\215;\1\356\13\346\370\221\60\311)j\343N"
|
||||
"\357\13\346\370\341$\247\250\215;\1\360\16\346\370E\271\64$Y\222%Y\264\23\361\20\346\370\225\212\216"
|
||||
"'\222\224dI\226d\71\14\362\15\346\370\343\234\64eI\226d\321N\363\16\346\370\241\60'MY\222"
|
||||
"%Y\264\23\364\17\346\370\221\60\311)S\226dI\26\355\4\365\16\346\370\225\212N\231\262$K\262h"
|
||||
"'\366\16\346\370\341$\247LY\222%Y\264\23\367\13\346\370Ysh\320\241\234\1\370\14\346\370\271M"
|
||||
"\221\322\42E;\1\371\17\346\370\343\234\222%Y\222%\221%\207\1\372\20\346\370\241\60\247dI\226d"
|
||||
"Id\311a\0\373\20\346\370\221\60\311\361,\311\222,\211,\71\14\374\20\346\370\341$\307\263$K\262"
|
||||
"$\262\344\60\0\375\21\346\370\241\60\247dI\226dI\26\15i\64\1\376\20\346\370\321\326!\312\222,"
|
||||
"\311\222!JS\0\377\21\346\370\341$\307\263$K\262$\213\206\64\232\0\0\0\0\4\377\377\0";
|
||||
255
Middlewares/u8g2Lib/src/u8g2_hvline.c
Normal file
255
Middlewares/u8g2Lib/src/u8g2_hvline.c
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
|
||||
u8g2_hvline.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Calltree
|
||||
|
||||
void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
u8g2->cb->draw_l90
|
||||
u8g2_draw_hv_line_2dir
|
||||
u8g2->ll_hvline(u8g2, x, y, len, dir);
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <assert.h>
|
||||
|
||||
/*==========================================================*/
|
||||
/* intersection procedure */
|
||||
|
||||
/*
|
||||
Description:
|
||||
clip range from pos a (included) with line len (a+len excluded) agains c (included) to d (excluded)
|
||||
Assumptions:
|
||||
len > 0
|
||||
c <= d (this is not checked)
|
||||
will return 0 if there is no intersection and if a > b
|
||||
|
||||
*/
|
||||
|
||||
static uint8_t u8g2_clip_intersection2(u8g2_uint_t *ap, u8g2_uint_t *len, u8g2_uint_t c, u8g2_uint_t d)
|
||||
{
|
||||
u8g2_uint_t a = *ap;
|
||||
u8g2_uint_t b;
|
||||
b = a;
|
||||
b += *len;
|
||||
|
||||
/*
|
||||
Description:
|
||||
clip range from a (included) to b (excluded) agains c (included) to d (excluded)
|
||||
Assumptions:
|
||||
a <= b (violation is checked and handled correctly)
|
||||
c <= d (this is not checked)
|
||||
will return 0 if there is no intersection and if a > b
|
||||
|
||||
optimized clipping: c is set to 0 --> 27 Oct 2018: again removed the c==0 assumption
|
||||
|
||||
replaced by uint8_t u8g2_clip_intersection2
|
||||
*/
|
||||
|
||||
/* handle the a>b case correctly. If code and time is critical, this could */
|
||||
/* be removed completly (be aware about memory curruption for wrong */
|
||||
/* arguments) or return 0 for a>b (will lead to skipped lines for wrong */
|
||||
/* arguments) */
|
||||
|
||||
/* removing the following if clause completly may lead to memory corruption of a>b */
|
||||
if ( a > b )
|
||||
{
|
||||
/* replacing this if with a simple "return 0;" will not handle the case with negative a */
|
||||
if ( a < d )
|
||||
{
|
||||
b = d;
|
||||
b--;
|
||||
}
|
||||
else
|
||||
{
|
||||
a = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* from now on, the asumption a <= b is ok */
|
||||
|
||||
if ( a >= d )
|
||||
return 0;
|
||||
if ( b <= c )
|
||||
return 0;
|
||||
if ( a < c )
|
||||
a = c;
|
||||
if ( b > d )
|
||||
b = d;
|
||||
|
||||
*ap = a;
|
||||
b -= a;
|
||||
*len = b;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*==========================================================*/
|
||||
/* draw procedures */
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the pixel buffer
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
This function first adjusts the y position to the local buffer. Then it
|
||||
will clip the line and call u8g2_draw_low_level_hv_line()
|
||||
|
||||
*/
|
||||
void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
|
||||
/* clipping happens before the display rotation */
|
||||
|
||||
/* transform to pixel buffer coordinates */
|
||||
y -= u8g2->pixel_curr_row;
|
||||
|
||||
u8g2->ll_hvline(u8g2, x, y, len, dir);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
This is the toplevel function for the hv line draw procedures.
|
||||
This function should be called by the user.
|
||||
|
||||
"dir" may have 4 directions: 0 (left to right), 1, 2, 3 (down up)
|
||||
*/
|
||||
void u8g2_DrawHVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
/* Make a call to the callback function (e.g. u8g2_draw_l90_r0). */
|
||||
/* The callback may rotate the hv line */
|
||||
/* after rotation this will call u8g2_draw_hv_line_4dir() */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
if ( u8g2->is_page_clip_window_intersection != 0 )
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
if ( len != 0 )
|
||||
{
|
||||
|
||||
/* convert to two directions */
|
||||
if ( len > 1 )
|
||||
{
|
||||
if ( dir == 2 )
|
||||
{
|
||||
x -= len;
|
||||
x++;
|
||||
}
|
||||
else if ( dir == 3 )
|
||||
{
|
||||
y -= len;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
dir &= 1;
|
||||
|
||||
/* clip against the user window */
|
||||
if ( dir == 0 )
|
||||
{
|
||||
if ( y < u8g2->user_y0 )
|
||||
return;
|
||||
if ( y >= u8g2->user_y1 )
|
||||
return;
|
||||
if ( u8g2_clip_intersection2(&x, &len, u8g2->user_x0, u8g2->user_x1) == 0 )
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( x < u8g2->user_x0 )
|
||||
return;
|
||||
if ( x >= u8g2->user_x1 )
|
||||
return;
|
||||
if ( u8g2_clip_intersection2(&y, &len, u8g2->user_y0, u8g2->user_y1) == 0 )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
u8g2->cb->draw_l90(u8g2, x, y, len, dir);
|
||||
}
|
||||
}
|
||||
|
||||
void u8g2_DrawHLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)
|
||||
{
|
||||
// #ifdef U8G2_WITH_INTERSECTION
|
||||
// if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
|
||||
// return;
|
||||
// #endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, len, 0);
|
||||
}
|
||||
|
||||
void u8g2_DrawVLine(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len)
|
||||
{
|
||||
// #ifdef U8G2_WITH_INTERSECTION
|
||||
// if ( u8g2_IsIntersection(u8g2, x, y, x+1, y+len) == 0 )
|
||||
// return;
|
||||
// #endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, len, 1);
|
||||
}
|
||||
|
||||
void u8g2_DrawPixel(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
#ifdef U8G2_WITH_INTERSECTION
|
||||
if ( y < u8g2->user_y0 )
|
||||
return;
|
||||
if ( y >= u8g2->user_y1 )
|
||||
return;
|
||||
if ( x < u8g2->user_x0 )
|
||||
return;
|
||||
if ( x >= u8g2->user_x1 )
|
||||
return;
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
u8g2_DrawHVLine(u8g2, x, y, 1, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
Assign the draw color for all drawing functions.
|
||||
color may be 0 or 1. The actual color is defined by the display.
|
||||
With color = 1 the drawing function will set the display memory to 1.
|
||||
For OLEDs this ususally means, that the pixel is enabled and the LED
|
||||
at the pixel is turned on.
|
||||
On an LCD it usually means that the LCD segment of the pixel is enabled,
|
||||
which absorbs the light.
|
||||
For eInk/ePaper it means black ink.
|
||||
|
||||
7 Jan 2017: Allow color value 2 for XOR operation.
|
||||
|
||||
*/
|
||||
void u8g2_SetDrawColor(u8g2_t *u8g2, uint8_t color)
|
||||
{
|
||||
u8g2->draw_color = color; /* u8g2_SetDrawColor: just assign the argument */
|
||||
if ( color >= 3 )
|
||||
u8g2->draw_color = 1; /* u8g2_SetDrawColor: make color as one if arg is invalid */
|
||||
}
|
||||
|
||||
150
Middlewares/u8g2Lib/src/u8g2_input_value.c
Normal file
150
Middlewares/u8g2Lib/src/u8g2_input_value.c
Normal file
@ -0,0 +1,150 @@
|
||||
/*
|
||||
|
||||
u8g2_input_value.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/*
|
||||
return:
|
||||
0: value is not changed (HOME/Break Button pressed)
|
||||
1: value has been updated
|
||||
*/
|
||||
|
||||
uint8_t u8g2_UserInterfaceInputValue(u8g2_t *u8g2, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post)
|
||||
{
|
||||
uint8_t line_height;
|
||||
uint8_t height;
|
||||
u8g2_uint_t pixel_height;
|
||||
u8g2_uint_t y, yy;
|
||||
u8g2_uint_t pixel_width;
|
||||
u8g2_uint_t x, xx;
|
||||
|
||||
uint8_t local_value = *value;
|
||||
//uint8_t r; /* not used ??? */
|
||||
uint8_t event;
|
||||
|
||||
/* only horizontal strings are supported, so force this here */
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
|
||||
/* force baseline position */
|
||||
u8g2_SetFontPosBaseline(u8g2);
|
||||
|
||||
/* calculate line height */
|
||||
line_height = u8g2_GetAscent(u8g2);
|
||||
line_height -= u8g2_GetDescent(u8g2);
|
||||
|
||||
|
||||
/* calculate overall height of the input value box */
|
||||
height = 1; /* value input line */
|
||||
height += u8x8_GetStringLineCnt(title);
|
||||
|
||||
/* calculate the height in pixel */
|
||||
pixel_height = height;
|
||||
pixel_height *= line_height;
|
||||
|
||||
|
||||
/* calculate offset from top */
|
||||
y = 0;
|
||||
if ( pixel_height < u8g2_GetDisplayHeight(u8g2) )
|
||||
{
|
||||
y = u8g2_GetDisplayHeight(u8g2);
|
||||
y -= pixel_height;
|
||||
y /= 2;
|
||||
}
|
||||
|
||||
/* calculate offset from left for the label */
|
||||
x = 0;
|
||||
pixel_width = u8g2_GetUTF8Width(u8g2, pre);
|
||||
pixel_width += u8g2_GetUTF8Width(u8g2, "0") * digits;
|
||||
pixel_width += u8g2_GetUTF8Width(u8g2, post);
|
||||
if ( pixel_width < u8g2_GetDisplayWidth(u8g2) )
|
||||
{
|
||||
x = u8g2_GetDisplayWidth(u8g2);
|
||||
x -= pixel_width;
|
||||
x /= 2;
|
||||
}
|
||||
|
||||
/* event loop */
|
||||
for(;;)
|
||||
{
|
||||
u8g2_FirstPage(u8g2);
|
||||
do
|
||||
{
|
||||
/* render */
|
||||
yy = y;
|
||||
yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title);
|
||||
xx = x;
|
||||
xx += u8g2_DrawUTF8(u8g2, xx, yy, pre);
|
||||
xx += u8g2_DrawUTF8(u8g2, xx, yy, u8x8_u8toa(local_value, digits));
|
||||
u8g2_DrawUTF8(u8g2, xx, yy, post);
|
||||
} while( u8g2_NextPage(u8g2) );
|
||||
|
||||
#ifdef U8G2_REF_MAN_PIC
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
for(;;)
|
||||
{
|
||||
event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
|
||||
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
|
||||
{
|
||||
*value = local_value;
|
||||
return 1;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
|
||||
{
|
||||
if ( local_value >= hi )
|
||||
local_value = lo;
|
||||
else
|
||||
local_value++;
|
||||
break;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
|
||||
{
|
||||
if ( local_value <= lo )
|
||||
local_value = hi;
|
||||
else
|
||||
local_value--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* never reached */
|
||||
//return r;
|
||||
}
|
||||
176
Middlewares/u8g2Lib/src/u8g2_intersection.c
Normal file
176
Middlewares/u8g2Lib/src/u8g2_intersection.c
Normal file
@ -0,0 +1,176 @@
|
||||
/*
|
||||
|
||||
u8g2_intersection.c
|
||||
|
||||
Intersection calculation, code taken from u8g_clip.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define U8G2_ALWAYS_INLINE __inline__ __attribute__((always_inline))
|
||||
#else
|
||||
#define U8G2_ALWAYS_INLINE
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(U8G2_WITH_INTERSECTION) || defined(U8G2_WITH_CLIP_WINDOW_SUPPORT)
|
||||
|
||||
#ifdef OLD_VERSION_WITH_SYMETRIC_BOUNDARIES
|
||||
|
||||
/*
|
||||
intersection assumptions:
|
||||
a1 <= a2 is always true
|
||||
|
||||
minimized version
|
||||
---1----0 1 b1 <= a2 && b1 > b2
|
||||
-----1--0 1 b2 >= a1 && b1 > b2
|
||||
---1-1--- 1 b1 <= a2 && b2 >= a1
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
calculate the intersection between a0/a1 and v0/v1
|
||||
The intersection check returns one if the range of a0/a1 has an intersection with v0/v1.
|
||||
The intersection check includes the boundary values v1 and a1.
|
||||
|
||||
The following asserts will succeed:
|
||||
assert( u8g2_is_intersection_decision_tree(4, 6, 7, 9) == 0 );
|
||||
assert( u8g2_is_intersection_decision_tree(4, 6, 6, 9) != 0 );
|
||||
assert( u8g2_is_intersection_decision_tree(6, 9, 4, 6) != 0 );
|
||||
assert( u8g2_is_intersection_decision_tree(7, 9, 4, 6) == 0 );
|
||||
*/
|
||||
|
||||
//static uint8_t U8G2_ALWAYS_INLINE u8g2_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
|
||||
static uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
|
||||
{
|
||||
if ( v0 <= a1 )
|
||||
{
|
||||
if ( v1 >= a0 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v0 > v1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v1 >= a0 )
|
||||
{
|
||||
if ( v0 > v1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* OLD_VERSION_WITH_SYMETRIC_BOUNDARIES */
|
||||
|
||||
|
||||
/*
|
||||
version with asymetric boundaries.
|
||||
a1 and v1 are excluded
|
||||
v0 == v1 is not support end return 1
|
||||
*/
|
||||
uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
|
||||
{
|
||||
if ( v0 < a1 ) // v0 <= a1
|
||||
{
|
||||
if ( v1 > a0 ) // v1 >= a0
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v0 > v1 ) // v0 > v1
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( v1 > a0 ) // v1 >= a0
|
||||
{
|
||||
if ( v0 > v1 ) // v0 > v1
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* upper limits are not included (asymetric boundaries) */
|
||||
uint8_t u8g2_IsIntersection(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1)
|
||||
{
|
||||
if ( u8g2_is_intersection_decision_tree(u8g2->user_y0, u8g2->user_y1, y0, y1) == 0 )
|
||||
return 0;
|
||||
|
||||
return u8g2_is_intersection_decision_tree(u8g2->user_x0, u8g2->user_x1, x0, x1);
|
||||
}
|
||||
|
||||
|
||||
#endif /* U8G2_WITH_INTERSECTION */
|
||||
|
||||
94
Middlewares/u8g2Lib/src/u8g2_kerning.c
Normal file
94
Middlewares/u8g2Lib/src/u8g2_kerning.c
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
|
||||
u8g2_kerning.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
/* this function is used as "u8g2_get_kerning_cb" */
|
||||
/*
|
||||
uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/* this function is used as "u8g2_get_kerning_cb" */
|
||||
uint8_t u8g2_GetKerning(U8X8_UNUSED u8g2_t *u8g2, u8g2_kerning_t *kerning, uint16_t e1, uint16_t e2)
|
||||
{
|
||||
uint16_t i1, i2, cnt, end;
|
||||
if ( kerning == NULL )
|
||||
return 0;
|
||||
|
||||
/* search for the encoding in the first table */
|
||||
cnt = kerning->first_table_cnt;
|
||||
cnt--; /* ignore the last element of the table, which is 0x0ffff */
|
||||
for( i1 = 0; i1 < cnt; i1++ )
|
||||
{
|
||||
if ( kerning->first_encoding_table[i1] == e1 )
|
||||
break;
|
||||
}
|
||||
if ( i1 >= cnt )
|
||||
return 0; /* e1 not part of the kerning table, return 0 */
|
||||
|
||||
/* get the upper index for i2 */
|
||||
end = kerning->index_to_second_table[i1+1];
|
||||
for( i2 = kerning->index_to_second_table[i1]; i2 < end; i2++ )
|
||||
{
|
||||
if ( kerning->second_encoding_table[i2] == e2 )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( i2 >= end )
|
||||
return 0; /* e2 not part of any pair with e1, return 0 */
|
||||
|
||||
return kerning->kerning_values[i2];
|
||||
}
|
||||
|
||||
uint8_t u8g2_GetKerningByTable(U8X8_UNUSED u8g2_t *u8g2, const uint16_t *kt, uint16_t e1, uint16_t e2)
|
||||
{
|
||||
uint16_t i;
|
||||
i = 0;
|
||||
if ( kt == NULL )
|
||||
return 0;
|
||||
for(;;)
|
||||
{
|
||||
if ( kt[i] == 0x0ffff )
|
||||
break;
|
||||
if ( kt[i] == e1 && kt[i+1] == e2 )
|
||||
return kt[i+2];
|
||||
i+=3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
92
Middlewares/u8g2Lib/src/u8g2_line.c
Normal file
92
Middlewares/u8g2Lib/src/u8g2_line.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
|
||||
u8g2_box.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
|
||||
void u8g2_DrawLine(u8g2_t *u8g2, u8g2_uint_t x1, u8g2_uint_t y1, u8g2_uint_t x2, u8g2_uint_t y2)
|
||||
{
|
||||
u8g2_uint_t tmp;
|
||||
u8g2_uint_t x,y;
|
||||
u8g2_uint_t dx, dy;
|
||||
u8g2_int_t err;
|
||||
u8g2_int_t ystep;
|
||||
|
||||
uint8_t swapxy = 0;
|
||||
|
||||
/* no intersection check at the moment, should be added... */
|
||||
|
||||
if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1;
|
||||
if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1;
|
||||
|
||||
if ( dy > dx )
|
||||
{
|
||||
swapxy = 1;
|
||||
tmp = dx; dx =dy; dy = tmp;
|
||||
tmp = x1; x1 =y1; y1 = tmp;
|
||||
tmp = x2; x2 =y2; y2 = tmp;
|
||||
}
|
||||
if ( x1 > x2 )
|
||||
{
|
||||
tmp = x1; x1 =x2; x2 = tmp;
|
||||
tmp = y1; y1 =y2; y2 = tmp;
|
||||
}
|
||||
err = dx >> 1;
|
||||
if ( y2 > y1 ) ystep = 1; else ystep = -1;
|
||||
y = y1;
|
||||
|
||||
#ifndef U8G2_16BIT
|
||||
if ( x2 == 255 )
|
||||
x2--;
|
||||
#else
|
||||
if ( x2 == 0xffff )
|
||||
x2--;
|
||||
#endif
|
||||
|
||||
for( x = x1; x <= x2; x++ )
|
||||
{
|
||||
if ( swapxy == 0 )
|
||||
u8g2_DrawPixel(u8g2, x, y);
|
||||
else
|
||||
u8g2_DrawPixel(u8g2, y, x);
|
||||
err -= (u8g2_uint_t)dy;
|
||||
if ( err < 0 )
|
||||
{
|
||||
y += (u8g2_uint_t)ystep;
|
||||
err += (u8g2_uint_t)dx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
371
Middlewares/u8g2Lib/src/u8g2_ll_hvline.c
Normal file
371
Middlewares/u8g2Lib/src/u8g2_ll_hvline.c
Normal file
@ -0,0 +1,371 @@
|
||||
/*
|
||||
|
||||
u8g2_ll_hvline.c
|
||||
|
||||
low level hvline
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*ptr |= or_mask
|
||||
*ptr ^= xor_mask
|
||||
|
||||
color = 0: or_mask = 1, xor_mask = 1
|
||||
color = 1: or_mask = 1, xor_mask = 0
|
||||
color = 2: or_mask = 0, xor_mask = 1
|
||||
|
||||
if ( color <= 1 )
|
||||
or_mask = mask;
|
||||
if ( color != 1 )
|
||||
xor_mask = mask;
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <assert.h>
|
||||
|
||||
/*=================================================*/
|
||||
/*
|
||||
u8g2_ll_hvline_vertical_top_lsb
|
||||
SSD13xx
|
||||
UC1701
|
||||
*/
|
||||
|
||||
|
||||
#ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos, mask;
|
||||
uint8_t or_mask, xor_mask;
|
||||
#ifdef __unix
|
||||
uint8_t *max_ptr = u8g2->tile_buf_ptr + u8g2_GetU8x8(u8g2)->display_info->tile_width*u8g2->tile_buf_height*8;
|
||||
#endif
|
||||
|
||||
//assert(x >= u8g2->buf_x0);
|
||||
//assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
|
||||
//assert(y >= u8g2->buf_y0);
|
||||
//assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
|
||||
|
||||
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
|
||||
bit_pos = y; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 1;
|
||||
mask <<= bit_pos;
|
||||
|
||||
or_mask = 0;
|
||||
xor_mask = 0;
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
or_mask = mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
xor_mask = mask;
|
||||
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset &= ~7;
|
||||
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
ptr += x;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
#ifdef __unix
|
||||
assert(ptr < max_ptr);
|
||||
#endif
|
||||
*ptr |= or_mask;
|
||||
*ptr ^= xor_mask;
|
||||
ptr++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
#ifdef __unix
|
||||
assert(ptr < max_ptr);
|
||||
#endif
|
||||
*ptr |= or_mask;
|
||||
*ptr ^= xor_mask;
|
||||
|
||||
bit_pos++;
|
||||
bit_pos &= 7;
|
||||
|
||||
len--;
|
||||
|
||||
if ( bit_pos == 0 )
|
||||
{
|
||||
ptr+=u8g2->pixel_buf_width; /* 6 Jan 17: Changed u8g2->width to u8g2->pixel_buf_width, issue #148 */
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
or_mask = 1;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
xor_mask = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
or_mask <<= 1;
|
||||
xor_mask <<= 1;
|
||||
}
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
|
||||
/*
|
||||
x,y position within the buffer
|
||||
*/
|
||||
static void u8g2_draw_pixel_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos, mask;
|
||||
|
||||
//assert(x >= u8g2->buf_x0);
|
||||
//assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
|
||||
//assert(y >= u8g2->buf_y0);
|
||||
//assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
|
||||
|
||||
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
|
||||
bit_pos = y; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 1;
|
||||
mask <<= bit_pos;
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset &= ~7;
|
||||
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
ptr += x;
|
||||
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
void u8g2_ll_hvline_vertical_top_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
if ( dir == 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
|
||||
x++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_vertical_top_lsb(u8g2, x, y);
|
||||
y++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
|
||||
/*=================================================*/
|
||||
/*
|
||||
u8g2_ll_hvline_horizontal_right_lsb
|
||||
ST7920
|
||||
*/
|
||||
|
||||
#ifdef U8G2_WITH_HVLINE_SPEED_OPTIMIZATION
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos;
|
||||
uint8_t mask;
|
||||
uint8_t tile_width = u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
|
||||
bit_pos = x; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 128;
|
||||
mask >>= bit_pos;
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset *= tile_width;
|
||||
offset += x>>3;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
mask >>= 1;
|
||||
if ( mask == 0 )
|
||||
{
|
||||
mask = 128;
|
||||
ptr++;
|
||||
}
|
||||
|
||||
//x++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
ptr += tile_width;
|
||||
//y++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#else /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
|
||||
|
||||
/*
|
||||
x,y position within the buffer
|
||||
*/
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
static void u8g2_draw_pixel_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y)
|
||||
{
|
||||
uint16_t offset;
|
||||
uint8_t *ptr;
|
||||
uint8_t bit_pos, mask;
|
||||
|
||||
//assert(x >= u8g2->buf_x0);
|
||||
//assert(x < u8g2_GetU8x8(u8g2)->display_info->tile_width*8);
|
||||
//assert(y >= u8g2->buf_y0);
|
||||
//assert(y < u8g2_GetU8x8(u8g2)->display_info->tile_height*8);
|
||||
|
||||
/* bytes are vertical, lsb on top (y=0), msb at bottom (y=7) */
|
||||
bit_pos = x; /* overflow truncate is ok here... */
|
||||
bit_pos &= 7; /* ... because only the lowest 3 bits are needed */
|
||||
mask = 128;
|
||||
mask >>= bit_pos;
|
||||
x >>= 3;
|
||||
|
||||
offset = y; /* y might be 8 or 16 bit, but we need 16 bit, so use a 16 bit variable */
|
||||
offset *= u8g2_GetU8x8(u8g2)->display_info->tile_width;
|
||||
offset += x;
|
||||
ptr = u8g2->tile_buf_ptr;
|
||||
ptr += offset;
|
||||
|
||||
|
||||
if ( u8g2->draw_color <= 1 )
|
||||
*ptr |= mask;
|
||||
if ( u8g2->draw_color != 1 )
|
||||
*ptr ^= mask;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
x,y Upper left position of the line within the local buffer (not the display!)
|
||||
len length of the line in pixel, len must not be 0
|
||||
dir 0: horizontal line (left to right)
|
||||
1: vertical line (top to bottom)
|
||||
asumption:
|
||||
all clipping done
|
||||
*/
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
void u8g2_ll_hvline_horizontal_right_lsb(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
if ( dir == 0 )
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
|
||||
x++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
do
|
||||
{
|
||||
u8g2_draw_pixel_horizontal_right_lsb(u8g2, x, y);
|
||||
y++;
|
||||
len--;
|
||||
} while( len != 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* U8G2_WITH_HVLINE_SPEED_OPTIMIZATION */
|
||||
197
Middlewares/u8g2Lib/src/u8g2_message.c
Normal file
197
Middlewares/u8g2Lib/src/u8g2_message.c
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
|
||||
u8g2_message.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
#define SPACE_BETWEEN_BUTTONS_IN_PIXEL 6
|
||||
#define SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL 3
|
||||
|
||||
uint8_t u8g2_draw_button_line(u8g2_t *u8g2, u8g2_uint_t y, u8g2_uint_t w, uint8_t cursor, const char *s)
|
||||
{
|
||||
u8g2_uint_t button_line_width;
|
||||
|
||||
uint8_t i;
|
||||
uint8_t cnt;
|
||||
uint8_t is_invert;
|
||||
|
||||
u8g2_uint_t d;
|
||||
u8g2_uint_t x;
|
||||
|
||||
cnt = u8x8_GetStringLineCnt(s);
|
||||
|
||||
|
||||
/* calculate the width of the button line */
|
||||
button_line_width = 0;
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
button_line_width += u8g2_GetUTF8Width(u8g2, u8x8_GetStringLineStart(i, s));
|
||||
}
|
||||
button_line_width += (cnt-1)*SPACE_BETWEEN_BUTTONS_IN_PIXEL; /* add some space between the buttons */
|
||||
|
||||
/* calculate the left offset */
|
||||
d = 0;
|
||||
if ( button_line_width < w )
|
||||
{
|
||||
d = w;
|
||||
d -= button_line_width;
|
||||
d /= 2;
|
||||
}
|
||||
|
||||
/* draw the buttons */
|
||||
x = d;
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
is_invert = 0;
|
||||
if ( i == cursor )
|
||||
is_invert = 1;
|
||||
|
||||
u8g2_DrawUTF8Line(u8g2, x, y, 0, u8x8_GetStringLineStart(i, s), 1, is_invert);
|
||||
x += u8g2_GetUTF8Width(u8g2, u8x8_GetStringLineStart(i, s));
|
||||
x += SPACE_BETWEEN_BUTTONS_IN_PIXEL;
|
||||
}
|
||||
|
||||
/* return the number of buttons */
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*
|
||||
title1: Multiple lines,separated by '\n'
|
||||
title2: A single line/string which is terminated by '\0' or '\n' . "title2" accepts the return value from u8x8_GetStringLineStart()
|
||||
title3: Multiple lines,separated by '\n'
|
||||
buttons: one more more buttons separated by '\n' and terminated with '\0'
|
||||
side effects:
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
u8g2_SetFontPosBaseline(u8g2);
|
||||
*/
|
||||
|
||||
uint8_t u8g2_UserInterfaceMessage(u8g2_t *u8g2, const char *title1, const char *title2, const char *title3, const char *buttons)
|
||||
{
|
||||
uint8_t height;
|
||||
uint8_t line_height;
|
||||
u8g2_uint_t pixel_height;
|
||||
u8g2_uint_t y, yy;
|
||||
|
||||
uint8_t cursor = 0;
|
||||
uint8_t button_cnt;
|
||||
uint8_t event;
|
||||
|
||||
/* only horizontal strings are supported, so force this here */
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
|
||||
/* force baseline position */
|
||||
u8g2_SetFontPosBaseline(u8g2);
|
||||
|
||||
|
||||
/* calculate line height */
|
||||
line_height = u8g2_GetAscent(u8g2);
|
||||
line_height -= u8g2_GetDescent(u8g2);
|
||||
|
||||
/* calculate overall height of the message box in lines*/
|
||||
height = 1; /* button line */
|
||||
height += u8x8_GetStringLineCnt(title1);
|
||||
if ( title2 != NULL )
|
||||
height++;
|
||||
height += u8x8_GetStringLineCnt(title3);
|
||||
|
||||
/* calculate the height in pixel */
|
||||
pixel_height = height;
|
||||
pixel_height *= line_height;
|
||||
|
||||
/* ... and add the space between the text and the buttons */
|
||||
pixel_height +=SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL;
|
||||
|
||||
/* calculate offset from top */
|
||||
y = 0;
|
||||
if ( pixel_height < u8g2_GetDisplayHeight(u8g2) )
|
||||
{
|
||||
y = u8g2_GetDisplayHeight(u8g2);
|
||||
y -= pixel_height;
|
||||
y /= 2;
|
||||
}
|
||||
y += u8g2_GetAscent(u8g2);
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
u8g2_FirstPage(u8g2);
|
||||
do
|
||||
{
|
||||
yy = y;
|
||||
/* draw message box */
|
||||
|
||||
yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title1);
|
||||
if ( title2 != NULL )
|
||||
{
|
||||
u8g2_DrawUTF8Line(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), title2, 0, 0);
|
||||
yy+=line_height;
|
||||
}
|
||||
yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title3);
|
||||
yy += SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL;
|
||||
|
||||
button_cnt = u8g2_draw_button_line(u8g2, yy, u8g2_GetDisplayWidth(u8g2), cursor, buttons);
|
||||
|
||||
} while( u8g2_NextPage(u8g2) );
|
||||
|
||||
#ifdef U8G2_REF_MAN_PIC
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
for(;;)
|
||||
{
|
||||
event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
|
||||
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
|
||||
return cursor+1;
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
|
||||
return 0;
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
|
||||
{
|
||||
cursor++;
|
||||
if ( cursor >= button_cnt )
|
||||
cursor = 0;
|
||||
break;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
|
||||
{
|
||||
if ( cursor == 0 )
|
||||
cursor = button_cnt;
|
||||
cursor--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* never reached */
|
||||
//return 0;
|
||||
}
|
||||
|
||||
346
Middlewares/u8g2Lib/src/u8g2_polygon.c
Normal file
346
Middlewares/u8g2Lib/src/u8g2_polygon.c
Normal file
@ -0,0 +1,346 @@
|
||||
/*
|
||||
|
||||
u8g22_polygon.c
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
|
||||
|
||||
|
||||
/*===========================================*/
|
||||
/* local definitions */
|
||||
|
||||
typedef int16_t pg_word_t;
|
||||
|
||||
|
||||
struct pg_point_struct
|
||||
{
|
||||
pg_word_t x;
|
||||
pg_word_t y;
|
||||
};
|
||||
|
||||
typedef struct _pg_struct pg_struct; /* forward declaration */
|
||||
|
||||
struct pg_edge_struct
|
||||
{
|
||||
pg_word_t x_direction; /* 1, if x2 is greater than x1, -1 otherwise */
|
||||
pg_word_t height;
|
||||
pg_word_t current_x_offset;
|
||||
pg_word_t error_offset;
|
||||
|
||||
/* --- line loop --- */
|
||||
pg_word_t current_y;
|
||||
pg_word_t max_y;
|
||||
pg_word_t current_x;
|
||||
pg_word_t error;
|
||||
|
||||
/* --- outer loop --- */
|
||||
uint8_t (*next_idx_fn)(pg_struct *pg, uint8_t i);
|
||||
uint8_t curr_idx;
|
||||
};
|
||||
|
||||
/* maximum number of points in the polygon */
|
||||
/* can be redefined, but highest possible value is 254 */
|
||||
#define PG_MAX_POINTS 6
|
||||
|
||||
/* index numbers for the pge structures below */
|
||||
#define PG_LEFT 0
|
||||
#define PG_RIGHT 1
|
||||
|
||||
|
||||
struct _pg_struct
|
||||
{
|
||||
struct pg_point_struct list[PG_MAX_POINTS];
|
||||
uint8_t cnt;
|
||||
uint8_t is_min_y_not_flat;
|
||||
pg_word_t total_scan_line_cnt;
|
||||
struct pg_edge_struct pge[2]; /* left and right line draw structures */
|
||||
};
|
||||
|
||||
|
||||
/*===========================================*/
|
||||
/* procedures, which should not be inlined (save as much flash ROM as possible */
|
||||
|
||||
#define PG_NOINLINE U8G2_NOINLINE
|
||||
|
||||
static uint8_t pge_Next(struct pg_edge_struct *pge) PG_NOINLINE;
|
||||
static uint8_t pg_inc(pg_struct *pg, uint8_t i) PG_NOINLINE;
|
||||
static uint8_t pg_dec(pg_struct *pg, uint8_t i) PG_NOINLINE;
|
||||
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx) PG_NOINLINE;
|
||||
static void pg_line_init(pg_struct * const pg, uint8_t pge_index) PG_NOINLINE;
|
||||
|
||||
/*===========================================*/
|
||||
/* line draw algorithm */
|
||||
|
||||
static uint8_t pge_Next(struct pg_edge_struct *pge)
|
||||
{
|
||||
if ( pge->current_y >= pge->max_y )
|
||||
return 0;
|
||||
|
||||
pge->current_x += pge->current_x_offset;
|
||||
pge->error += pge->error_offset;
|
||||
if ( pge->error > 0 )
|
||||
{
|
||||
pge->current_x += pge->x_direction;
|
||||
pge->error -= pge->height;
|
||||
}
|
||||
|
||||
pge->current_y++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* assumes y2 > y1 */
|
||||
static void pge_Init(struct pg_edge_struct *pge, pg_word_t x1, pg_word_t y1, pg_word_t x2, pg_word_t y2)
|
||||
{
|
||||
pg_word_t dx = x2 - x1;
|
||||
pg_word_t width;
|
||||
|
||||
pge->height = y2 - y1;
|
||||
pge->max_y = y2;
|
||||
pge->current_y = y1;
|
||||
pge->current_x = x1;
|
||||
|
||||
if ( dx >= 0 )
|
||||
{
|
||||
pge->x_direction = 1;
|
||||
width = dx;
|
||||
pge->error = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pge->x_direction = -1;
|
||||
width = -dx;
|
||||
pge->error = 1 - pge->height;
|
||||
}
|
||||
|
||||
pge->current_x_offset = dx / pge->height;
|
||||
pge->error_offset = width % pge->height;
|
||||
}
|
||||
|
||||
/*===========================================*/
|
||||
/* convex polygon algorithm */
|
||||
|
||||
static uint8_t pg_inc(pg_struct *pg, uint8_t i)
|
||||
{
|
||||
i++;
|
||||
if ( i >= pg->cnt )
|
||||
i = 0;
|
||||
return i;
|
||||
}
|
||||
|
||||
static uint8_t pg_dec(pg_struct *pg, uint8_t i)
|
||||
{
|
||||
i--;
|
||||
if ( i >= pg->cnt )
|
||||
i = pg->cnt-1;
|
||||
return i;
|
||||
}
|
||||
|
||||
static void pg_expand_min_y(pg_struct *pg, pg_word_t min_y, uint8_t pge_idx)
|
||||
{
|
||||
uint8_t i = pg->pge[pge_idx].curr_idx;
|
||||
for(;;)
|
||||
{
|
||||
i = pg->pge[pge_idx].next_idx_fn(pg, i);
|
||||
if ( pg->list[i].y != min_y )
|
||||
break;
|
||||
pg->pge[pge_idx].curr_idx = i;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t pg_prepare(pg_struct *pg)
|
||||
{
|
||||
pg_word_t max_y;
|
||||
pg_word_t min_y;
|
||||
uint8_t i;
|
||||
|
||||
/* setup the next index procedures */
|
||||
pg->pge[PG_RIGHT].next_idx_fn = pg_inc;
|
||||
pg->pge[PG_LEFT].next_idx_fn = pg_dec;
|
||||
|
||||
/* search for highest and lowest point */
|
||||
max_y = pg->list[0].y;
|
||||
min_y = pg->list[0].y;
|
||||
pg->pge[PG_LEFT].curr_idx = 0;
|
||||
for( i = 1; i < pg->cnt; i++ )
|
||||
{
|
||||
if ( max_y < pg->list[i].y )
|
||||
{
|
||||
max_y = pg->list[i].y;
|
||||
}
|
||||
if ( min_y > pg->list[i].y )
|
||||
{
|
||||
pg->pge[PG_LEFT].curr_idx = i;
|
||||
min_y = pg->list[i].y;
|
||||
}
|
||||
}
|
||||
|
||||
/* calculate total number of scan lines */
|
||||
pg->total_scan_line_cnt = max_y;
|
||||
pg->total_scan_line_cnt -= min_y;
|
||||
|
||||
/* exit if polygon height is zero */
|
||||
if ( pg->total_scan_line_cnt == 0 )
|
||||
return 0;
|
||||
|
||||
/* if the minimum y side is flat, try to find the lowest and highest x points */
|
||||
pg->pge[PG_RIGHT].curr_idx = pg->pge[PG_LEFT].curr_idx;
|
||||
pg_expand_min_y(pg, min_y, PG_RIGHT);
|
||||
pg_expand_min_y(pg, min_y, PG_LEFT);
|
||||
|
||||
/* check if the min side is really flat (depends on the x values) */
|
||||
pg->is_min_y_not_flat = 1;
|
||||
if ( pg->list[pg->pge[PG_LEFT].curr_idx].x != pg->list[pg->pge[PG_RIGHT].curr_idx].x )
|
||||
{
|
||||
pg->is_min_y_not_flat = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
pg->total_scan_line_cnt--;
|
||||
if ( pg->total_scan_line_cnt == 0 )
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void pg_hline(pg_struct *pg, u8g2_t *u8g2)
|
||||
{
|
||||
pg_word_t x1, x2, y;
|
||||
x1 = pg->pge[PG_LEFT].current_x;
|
||||
x2 = pg->pge[PG_RIGHT].current_x;
|
||||
y = pg->pge[PG_RIGHT].current_y;
|
||||
|
||||
if ( y < 0 )
|
||||
return;
|
||||
if ( y >= (pg_word_t)u8g2_GetDisplayHeight(u8g2) ) // does not work for 256x64 display???
|
||||
return;
|
||||
if ( x1 < x2 )
|
||||
{
|
||||
if ( x2 < 0 )
|
||||
return;
|
||||
if ( x1 >= (pg_word_t)u8g2_GetDisplayWidth(u8g2) )
|
||||
return;
|
||||
if ( x1 < 0 )
|
||||
x1 = 0;
|
||||
if ( x2 >= (pg_word_t)u8g2_GetDisplayWidth(u8g2) )
|
||||
x2 = u8g2_GetDisplayWidth(u8g2);
|
||||
u8g2_DrawHLine(u8g2, x1, y, x2 - x1);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( x1 < 0 )
|
||||
return;
|
||||
if ( x2 >= (pg_word_t)u8g2_GetDisplayWidth(u8g2) )
|
||||
return;
|
||||
if ( x2 < 0 )
|
||||
x1 = 0;
|
||||
if ( x1 >= (pg_word_t)u8g2_GetDisplayWidth(u8g2) )
|
||||
x1 = u8g2_GetDisplayWidth(u8g2);
|
||||
u8g2_DrawHLine(u8g2, x2, y, x1 - x2);
|
||||
}
|
||||
}
|
||||
|
||||
static void pg_line_init(pg_struct * const pg, uint8_t pge_index)
|
||||
{
|
||||
struct pg_edge_struct *pge = pg->pge+pge_index;
|
||||
uint8_t idx;
|
||||
pg_word_t x1;
|
||||
pg_word_t y1;
|
||||
pg_word_t x2;
|
||||
pg_word_t y2;
|
||||
|
||||
idx = pge->curr_idx;
|
||||
y1 = pg->list[idx].y;
|
||||
x1 = pg->list[idx].x;
|
||||
idx = pge->next_idx_fn(pg, idx);
|
||||
y2 = pg->list[idx].y;
|
||||
x2 = pg->list[idx].x;
|
||||
pge->curr_idx = idx;
|
||||
|
||||
pge_Init(pge, x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
static void pg_exec(pg_struct *pg, u8g2_t *u8g2)
|
||||
{
|
||||
pg_word_t i = pg->total_scan_line_cnt;
|
||||
|
||||
/* first line is skipped if the min y line is not flat */
|
||||
pg_line_init(pg, PG_LEFT);
|
||||
pg_line_init(pg, PG_RIGHT);
|
||||
|
||||
if ( pg->is_min_y_not_flat != 0 )
|
||||
{
|
||||
pge_Next(&(pg->pge[PG_LEFT]));
|
||||
pge_Next(&(pg->pge[PG_RIGHT]));
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
pg_hline(pg, u8g2);
|
||||
while ( pge_Next(&(pg->pge[PG_LEFT])) == 0 )
|
||||
{
|
||||
pg_line_init(pg, PG_LEFT);
|
||||
}
|
||||
while ( pge_Next(&(pg->pge[PG_RIGHT])) == 0 )
|
||||
{
|
||||
pg_line_init(pg, PG_RIGHT);
|
||||
}
|
||||
i--;
|
||||
} while( i > 0 );
|
||||
}
|
||||
|
||||
/*===========================================*/
|
||||
/* API procedures */
|
||||
|
||||
static void pg_ClearPolygonXY(pg_struct *pg)
|
||||
{
|
||||
pg->cnt = 0;
|
||||
}
|
||||
|
||||
static void pg_AddPolygonXY(pg_struct *pg, int16_t x, int16_t y)
|
||||
{
|
||||
if ( pg->cnt < PG_MAX_POINTS )
|
||||
{
|
||||
pg->list[pg->cnt].x = x;
|
||||
pg->list[pg->cnt].y = y;
|
||||
pg->cnt++;
|
||||
}
|
||||
}
|
||||
|
||||
static void pg_DrawPolygon(pg_struct *pg, u8g2_t *u8g2)
|
||||
{
|
||||
if ( pg_prepare(pg) == 0 )
|
||||
return;
|
||||
pg_exec(pg, u8g2);
|
||||
}
|
||||
|
||||
pg_struct u8g2_pg;
|
||||
|
||||
void u8g2_ClearPolygonXY(void)
|
||||
{
|
||||
pg_ClearPolygonXY(&u8g2_pg);
|
||||
}
|
||||
|
||||
void u8g2_AddPolygonXY(U8X8_UNUSED u8g2_t *u8g2, int16_t x, int16_t y)
|
||||
{
|
||||
pg_AddPolygonXY(&u8g2_pg, x, y);
|
||||
}
|
||||
|
||||
void u8g2_DrawPolygon(u8g2_t *u8g2)
|
||||
{
|
||||
pg_DrawPolygon(&u8g2_pg, u8g2);
|
||||
}
|
||||
|
||||
void u8g2_DrawTriangle(u8g2_t *u8g2, int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2)
|
||||
{
|
||||
u8g2_ClearPolygonXY();
|
||||
u8g2_AddPolygonXY(u8g2, x0, y0);
|
||||
u8g2_AddPolygonXY(u8g2, x1, y1);
|
||||
u8g2_AddPolygonXY(u8g2, x2, y2);
|
||||
u8g2_DrawPolygon(u8g2);
|
||||
}
|
||||
|
||||
284
Middlewares/u8g2Lib/src/u8g2_selection_list.c
Normal file
284
Middlewares/u8g2Lib/src/u8g2_selection_list.c
Normal file
@ -0,0 +1,284 @@
|
||||
/*
|
||||
|
||||
u8g2_selection_list.c
|
||||
|
||||
selection list with scroll option
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
|
||||
#define MY_BORDER_SIZE 1
|
||||
|
||||
|
||||
/*
|
||||
Draw a string at x,y
|
||||
Center string within w (left adjust if w < pixel len of s)
|
||||
|
||||
Side effects:
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
u8g2_SetFontPosBaseline(u8g2);
|
||||
|
||||
*/
|
||||
void u8g2_DrawUTF8Line(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, const char *s, uint8_t border_size, uint8_t is_invert)
|
||||
{
|
||||
u8g2_uint_t d, str_width;
|
||||
u8g2_uint_t fx, fy, fw, fh;
|
||||
|
||||
/* only horizontal strings are supported, so force this here */
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
|
||||
/* revert y position back to baseline ref */
|
||||
y += u8g2->font_calc_vref(u8g2);
|
||||
|
||||
/* calculate the width of the string in pixel */
|
||||
str_width = u8g2_GetUTF8Width(u8g2, s);
|
||||
|
||||
/* calculate delta d within the box */
|
||||
d = 0;
|
||||
if ( str_width < w )
|
||||
{
|
||||
d = w;
|
||||
d -=str_width;
|
||||
d /= 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
w = str_width;
|
||||
}
|
||||
|
||||
/* caluclate text box */
|
||||
fx = x;
|
||||
fy = y - u8g2_GetAscent(u8g2) ;
|
||||
fw = w;
|
||||
fh = u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2) ;
|
||||
|
||||
/* draw the box, if inverted */
|
||||
u8g2_SetDrawColor(u8g2, 1);
|
||||
if ( is_invert )
|
||||
{
|
||||
u8g2_DrawBox(u8g2, fx, fy, fw, fh);
|
||||
}
|
||||
|
||||
/* draw the frame */
|
||||
while( border_size > 0 )
|
||||
{
|
||||
fx--;
|
||||
fy--;
|
||||
fw +=2;
|
||||
fh +=2;
|
||||
u8g2_DrawFrame(u8g2, fx, fy, fw, fh );
|
||||
border_size--;
|
||||
}
|
||||
|
||||
if ( is_invert )
|
||||
{
|
||||
u8g2_SetDrawColor(u8g2, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
u8g2_SetDrawColor(u8g2, 1);
|
||||
}
|
||||
|
||||
/* draw the text */
|
||||
u8g2_DrawUTF8(u8g2, x+d, y, s);
|
||||
|
||||
/* revert draw color */
|
||||
u8g2_SetDrawColor(u8g2, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
draw several lines at position x,y.
|
||||
lines are stored in s and must be separated with '\n'.
|
||||
lines can be centered with respect to "w"
|
||||
if s == NULL nothing is drawn and 0 is returned
|
||||
returns the number of lines in s multiplied with line_height
|
||||
*/
|
||||
u8g2_uint_t u8g2_DrawUTF8Lines(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t line_height, const char *s)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t cnt;
|
||||
u8g2_uint_t yy = 0;
|
||||
cnt = u8x8_GetStringLineCnt(s);
|
||||
//printf("str=%s\n", s);
|
||||
//printf("cnt=%d, y=%d, line_height=%d\n", cnt, y, line_height);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
//printf(" i=%d, y=%d, line_height=%d\n", i, y, line_height);
|
||||
u8g2_DrawUTF8Line(u8g2, x, y, w, u8x8_GetStringLineStart(i, s), 0, 0);
|
||||
y+=line_height;
|
||||
yy+=line_height;
|
||||
}
|
||||
return yy;
|
||||
}
|
||||
|
||||
/*
|
||||
selection list with string line
|
||||
returns line height
|
||||
*/
|
||||
static u8g2_uint_t u8g2_draw_selection_list_line(u8g2_t *u8g2, u8sl_t *u8sl, u8g2_uint_t y, uint8_t idx, const char *s) U8G2_NOINLINE;
|
||||
static u8g2_uint_t u8g2_draw_selection_list_line(u8g2_t *u8g2, u8sl_t *u8sl, u8g2_uint_t y, uint8_t idx, const char *s)
|
||||
{
|
||||
//u8g2_uint_t yy;
|
||||
uint8_t border_size = 0;
|
||||
uint8_t is_invert = 0;
|
||||
|
||||
u8g2_uint_t line_height = u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2)+MY_BORDER_SIZE;
|
||||
|
||||
/* calculate offset from display upper border */
|
||||
//yy = idx;
|
||||
//yy -= u8sl->first_pos;
|
||||
//yy *= line_height;
|
||||
//yy += y;
|
||||
|
||||
/* check whether this is the current cursor line */
|
||||
if ( idx == u8sl->current_pos )
|
||||
{
|
||||
border_size = MY_BORDER_SIZE;
|
||||
is_invert = 1;
|
||||
}
|
||||
|
||||
/* get the line from the array */
|
||||
s = u8x8_GetStringLineStart(idx, s);
|
||||
|
||||
/* draw the line */
|
||||
if ( s == NULL )
|
||||
s = "";
|
||||
u8g2_DrawUTF8Line(u8g2, MY_BORDER_SIZE, y, u8g2_GetDisplayWidth(u8g2)-2*MY_BORDER_SIZE, s, border_size, is_invert);
|
||||
return line_height;
|
||||
}
|
||||
|
||||
void u8g2_DrawSelectionList(u8g2_t *u8g2, u8sl_t *u8sl, u8g2_uint_t y, const char *s)
|
||||
{
|
||||
uint8_t i;
|
||||
for( i = 0; i < u8sl->visible; i++ )
|
||||
{
|
||||
y += u8g2_draw_selection_list_line(u8g2, u8sl, y, i+u8sl->first_pos, s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
title: NULL for no title, valid str for title line. Can contain mutliple lines, separated by '\n'
|
||||
start_pos: default position for the cursor, first line is 1.
|
||||
sl: string list (list of strings separated by \n)
|
||||
returns 0 if user has pressed the home key
|
||||
returns the selected line if user has pressed the select key
|
||||
side effects:
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
u8g2_SetFontPosBaseline(u8g2);
|
||||
|
||||
*/
|
||||
uint8_t u8g2_UserInterfaceSelectionList(u8g2_t *u8g2, const char *title, uint8_t start_pos, const char *sl)
|
||||
{
|
||||
u8sl_t u8sl;
|
||||
u8g2_uint_t yy;
|
||||
|
||||
uint8_t event;
|
||||
|
||||
u8g2_uint_t line_height = u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2)+MY_BORDER_SIZE;
|
||||
|
||||
uint8_t title_lines = u8x8_GetStringLineCnt(title);
|
||||
uint8_t display_lines;
|
||||
|
||||
|
||||
if ( start_pos > 0 ) /* issue 112 */
|
||||
start_pos--; /* issue 112 */
|
||||
|
||||
|
||||
if ( title_lines > 0 )
|
||||
{
|
||||
display_lines = (u8g2_GetDisplayHeight(u8g2)-3) / line_height;
|
||||
u8sl.visible = display_lines;
|
||||
u8sl.visible -= title_lines;
|
||||
}
|
||||
else
|
||||
{
|
||||
display_lines = u8g2_GetDisplayHeight(u8g2) / line_height;
|
||||
u8sl.visible = display_lines;
|
||||
}
|
||||
|
||||
u8sl.total = u8x8_GetStringLineCnt(sl);
|
||||
u8sl.first_pos = 0;
|
||||
u8sl.current_pos = start_pos;
|
||||
|
||||
if ( u8sl.current_pos >= u8sl.total )
|
||||
u8sl.current_pos = u8sl.total-1;
|
||||
if ( u8sl.first_pos+u8sl.visible <= u8sl.current_pos )
|
||||
u8sl.first_pos = u8sl.current_pos-u8sl.visible+1;
|
||||
|
||||
u8g2_SetFontPosBaseline(u8g2);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
u8g2_FirstPage(u8g2);
|
||||
do
|
||||
{
|
||||
yy = u8g2_GetAscent(u8g2);
|
||||
if ( title_lines > 0 )
|
||||
{
|
||||
yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title);
|
||||
|
||||
u8g2_DrawHLine(u8g2, 0, yy-line_height- u8g2_GetDescent(u8g2) + 1, u8g2_GetDisplayWidth(u8g2));
|
||||
|
||||
yy += 3;
|
||||
}
|
||||
u8g2_DrawSelectionList(u8g2, &u8sl, yy, sl);
|
||||
} while( u8g2_NextPage(u8g2) );
|
||||
|
||||
#ifdef U8G2_REF_MAN_PIC
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
|
||||
for(;;)
|
||||
{
|
||||
event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
|
||||
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
|
||||
return u8sl.current_pos+1; /* +1, issue 112 */
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
|
||||
return 0; /* issue 112: return 0 instead of start_pos */
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
|
||||
{
|
||||
u8sl_Next(&u8sl);
|
||||
break;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
|
||||
{
|
||||
u8sl_Prev(&u8sl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
468
Middlewares/u8g2Lib/src/u8g2_setup.c
Normal file
468
Middlewares/u8g2Lib/src/u8g2_setup.c
Normal file
@ -0,0 +1,468 @@
|
||||
/*
|
||||
|
||||
u8g2_setup.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
/*============================================*/
|
||||
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
|
||||
void u8g2_SetMaxClipWindow(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->clip_x0 = 0;
|
||||
u8g2->clip_y0 = 0;
|
||||
u8g2->clip_x1 = (u8g2_uint_t)~(u8g2_uint_t)0;
|
||||
u8g2->clip_y1 = (u8g2_uint_t)~(u8g2_uint_t)0;
|
||||
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_SetClipWindow(u8g2_t *u8g2, u8g2_uint_t clip_x0, u8g2_uint_t clip_y0, u8g2_uint_t clip_x1, u8g2_uint_t clip_y1 )
|
||||
{
|
||||
u8g2->clip_x0 = clip_x0;
|
||||
u8g2->clip_y0 = clip_y0;
|
||||
u8g2->clip_x1 = clip_x1;
|
||||
u8g2->clip_y1 = clip_y1;
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*============================================*/
|
||||
/*
|
||||
This procedure is called after setting up the display (u8x8 structure).
|
||||
--> This is the central init procedure for u8g2 object
|
||||
*/
|
||||
void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_draw_ll_hvline_cb ll_hvline_cb, const u8g2_cb_t *u8g2_cb)
|
||||
{
|
||||
u8g2->font = NULL;
|
||||
//u8g2->kerning = NULL;
|
||||
//u8g2->get_kerning_cb = u8g2_GetNullKerning;
|
||||
|
||||
//u8g2->ll_hvline = u8g2_ll_hvline_vertical_top_lsb;
|
||||
u8g2->ll_hvline = ll_hvline_cb;
|
||||
|
||||
u8g2->tile_buf_ptr = buf;
|
||||
u8g2->tile_buf_height = tile_buf_height;
|
||||
|
||||
u8g2->tile_curr_row = 0;
|
||||
|
||||
u8g2->font_decode.is_transparent = 0; /* issue 443 */
|
||||
u8g2->bitmap_transparency = 0;
|
||||
|
||||
u8g2->font_height_mode = 0; /* issue 2046 */
|
||||
u8g2->draw_color = 1;
|
||||
u8g2->is_auto_page_clear = 1;
|
||||
|
||||
u8g2->cb = u8g2_cb;
|
||||
u8g2->cb->update_dimension(u8g2);
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_SetMaxClipWindow(u8g2); /* assign a clip window and call the update() procedure */
|
||||
#else
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
#endif
|
||||
|
||||
u8g2_SetFontPosBaseline(u8g2); /* issue 195 */
|
||||
|
||||
#ifdef U8G2_WITH_FONT_ROTATION
|
||||
u8g2->font_decode.dir = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
Usually the display rotation is set initially, but it could be done later also
|
||||
u8g2_cb can be U8G2_R0..U8G2_R3
|
||||
*/
|
||||
void u8g2_SetDisplayRotation(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
|
||||
{
|
||||
u8g2->cb = u8g2_cb;
|
||||
u8g2->cb->update_dimension(u8g2);
|
||||
u8g2->cb->update_page_win(u8g2);
|
||||
}
|
||||
|
||||
/*============================================*/
|
||||
|
||||
void u8g2_SendF(u8g2_t * u8g2, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
u8x8_cad_vsendf(u8g2_GetU8x8(u8g2), fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
/*
|
||||
update dimension:
|
||||
calculate the following variables:
|
||||
u8g2_uint_t buf_x0; left corner of the buffer
|
||||
u8g2_uint_t buf_x1; right corner of the buffer (excluded)
|
||||
u8g2_uint_t buf_y0;
|
||||
u8g2_uint_t buf_y1;
|
||||
*/
|
||||
|
||||
static void u8g2_update_dimension_common(u8g2_t *u8g2)
|
||||
{
|
||||
const u8x8_display_info_t *display_info = u8g2_GetU8x8(u8g2)->display_info;
|
||||
u8g2_uint_t t;
|
||||
|
||||
t = u8g2->tile_buf_height;
|
||||
t *= 8;
|
||||
u8g2->pixel_buf_height = t;
|
||||
|
||||
t = display_info->tile_width;
|
||||
#ifndef U8G2_16BIT
|
||||
if ( t >= 32 )
|
||||
t = 31;
|
||||
#endif
|
||||
t *= 8;
|
||||
u8g2->pixel_buf_width = t;
|
||||
|
||||
t = u8g2->tile_curr_row;
|
||||
t *= 8;
|
||||
u8g2->pixel_curr_row = t;
|
||||
|
||||
t = u8g2->tile_buf_height;
|
||||
/* handle the case, where the buffer is larger than the (remaining) part of the display */
|
||||
if ( t + u8g2->tile_curr_row > display_info->tile_height )
|
||||
t = display_info->tile_height - u8g2->tile_curr_row;
|
||||
t *= 8;
|
||||
|
||||
u8g2->buf_y0 = u8g2->pixel_curr_row;
|
||||
u8g2->buf_y1 = u8g2->buf_y0;
|
||||
u8g2->buf_y1 += t;
|
||||
|
||||
|
||||
#ifdef U8G2_16BIT
|
||||
u8g2->width = display_info->pixel_width;
|
||||
u8g2->height = display_info->pixel_height;
|
||||
#else
|
||||
u8g2->width = 240;
|
||||
if ( display_info->pixel_width <= 240 )
|
||||
u8g2->width = display_info->pixel_width;
|
||||
u8g2->height = display_info->pixel_height;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
/*==========================================================*/
|
||||
/* apply clip window */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
static void u8g2_apply_clip_window(u8g2_t *u8g2)
|
||||
{
|
||||
/* check aganst the current user_??? window */
|
||||
if ( u8g2_IsIntersection(u8g2, u8g2->clip_x0, u8g2->clip_y0, u8g2->clip_x1, u8g2->clip_y1) == 0 )
|
||||
{
|
||||
u8g2->is_page_clip_window_intersection = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8g2->is_page_clip_window_intersection = 1;
|
||||
|
||||
if ( u8g2->user_x0 < u8g2->clip_x0 )
|
||||
u8g2->user_x0 = u8g2->clip_x0;
|
||||
if ( u8g2->user_x1 > u8g2->clip_x1 )
|
||||
u8g2->user_x1 = u8g2->clip_x1;
|
||||
if ( u8g2->user_y0 < u8g2->clip_y0 )
|
||||
u8g2->user_y0 = u8g2->clip_y0;
|
||||
if ( u8g2->user_y1 > u8g2->clip_y1 )
|
||||
u8g2->user_y1 = u8g2->clip_y1;
|
||||
}
|
||||
}
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
|
||||
/*==========================================================*/
|
||||
|
||||
|
||||
void u8g2_update_dimension_r0(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r0(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->user_x0 = 0;
|
||||
u8g2->user_x1 = u8g2->width; /* pixel_buf_width replaced with width */
|
||||
|
||||
u8g2->user_y0 = u8g2->buf_y0;
|
||||
u8g2->user_y1 = u8g2->buf_y1;
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
|
||||
void u8g2_update_dimension_r1(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
|
||||
u8g2->height = u8g2_GetU8x8(u8g2)->display_info->pixel_width;
|
||||
u8g2->width = u8g2_GetU8x8(u8g2)->display_info->pixel_height;
|
||||
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r1(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->user_x0 = u8g2->buf_y0;
|
||||
u8g2->user_x1 = u8g2->buf_y1;
|
||||
|
||||
u8g2->user_y0 = 0;
|
||||
u8g2->user_y1 = u8g2->height; /* pixel_buf_width replaced with height (which is the real pixel width) */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
void u8g2_update_dimension_r2(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r2(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2->user_x0 = 0;
|
||||
u8g2->user_x1 = u8g2->width; /* pixel_buf_width replaced with width */
|
||||
|
||||
/* there are ases where the height is not a multiple of 8. */
|
||||
/* in such a case u8g2->buf_y1 might be heigher than u8g2->height */
|
||||
u8g2->user_y0 = 0;
|
||||
if ( u8g2->height >= u8g2->buf_y1 )
|
||||
u8g2->user_y0 = u8g2->height - u8g2->buf_y1;
|
||||
u8g2->user_y1 = u8g2->height - u8g2->buf_y0;
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
|
||||
void u8g2_update_dimension_r3(u8g2_t *u8g2)
|
||||
{
|
||||
u8g2_update_dimension_common(u8g2);
|
||||
|
||||
u8g2->height = u8g2_GetU8x8(u8g2)->display_info->pixel_width;
|
||||
u8g2->width = u8g2_GetU8x8(u8g2)->display_info->pixel_height;
|
||||
|
||||
}
|
||||
|
||||
void u8g2_update_page_win_r3(u8g2_t *u8g2)
|
||||
{
|
||||
/* there are ases where the height is not a multiple of 8. */
|
||||
/* in such a case u8g2->buf_y1 might be heigher than u8g2->width */
|
||||
u8g2->user_x0 = 0;
|
||||
if ( u8g2->width >= u8g2->buf_y1 )
|
||||
u8g2->user_x0 = u8g2->width - u8g2->buf_y1;
|
||||
u8g2->user_x1 = u8g2->width - u8g2->buf_y0;
|
||||
|
||||
u8g2->user_y0 = 0;
|
||||
u8g2->user_y1 = u8g2->height; /* pixel_buf_width replaced with height (pixel_width) */
|
||||
|
||||
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
|
||||
u8g2_apply_clip_window(u8g2);
|
||||
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
|
||||
}
|
||||
|
||||
|
||||
/*============================================*/
|
||||
extern void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);
|
||||
|
||||
|
||||
void u8g2_draw_l90_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
#ifdef __unix
|
||||
assert( dir <= 1 );
|
||||
#endif
|
||||
u8g2_draw_hv_line_2dir(u8g2, x, y, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_l90_mirrorr_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx;
|
||||
xx = u8g2->width;
|
||||
xx -= x;
|
||||
if ( (dir & 1) == 0 )
|
||||
{
|
||||
xx -= len;
|
||||
}
|
||||
else
|
||||
{
|
||||
xx--;
|
||||
}
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, y, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_mirror_vertical_r0(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t yy;
|
||||
yy = u8g2->height;
|
||||
yy -= y;
|
||||
if ( (dir & 1) == 1 )
|
||||
{
|
||||
yy -= len;
|
||||
}
|
||||
else
|
||||
{
|
||||
yy--;
|
||||
}
|
||||
u8g2_draw_hv_line_2dir(u8g2, x, yy, len, dir);
|
||||
}
|
||||
|
||||
/* dir = 0 or 1 */
|
||||
void u8g2_draw_l90_r1(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx, yy;
|
||||
|
||||
#ifdef __unix
|
||||
assert( dir <= 1 );
|
||||
#endif
|
||||
|
||||
yy = x;
|
||||
|
||||
xx = u8g2->height;
|
||||
xx -= y;
|
||||
xx--;
|
||||
|
||||
dir ++;
|
||||
if ( dir == 2 )
|
||||
{
|
||||
xx -= len;
|
||||
xx++;
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_l90_r2(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx, yy;
|
||||
|
||||
/*
|
||||
yy = u8g2->height;
|
||||
yy -= y;
|
||||
yy--;
|
||||
|
||||
xx = u8g2->width;
|
||||
xx -= x;
|
||||
xx--;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
xx -= len;
|
||||
xx++;
|
||||
}
|
||||
else if ( dir == 1 )
|
||||
{
|
||||
yy -= len;
|
||||
yy++;
|
||||
}
|
||||
*/
|
||||
|
||||
yy = u8g2->height;
|
||||
yy -= y;
|
||||
|
||||
xx = u8g2->width;
|
||||
xx -= x;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
yy--;
|
||||
xx -= len;
|
||||
}
|
||||
else if ( dir == 1 )
|
||||
{
|
||||
xx--;
|
||||
yy -= len;
|
||||
}
|
||||
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
|
||||
}
|
||||
|
||||
void u8g2_draw_l90_r3(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir)
|
||||
{
|
||||
u8g2_uint_t xx, yy;
|
||||
|
||||
xx = y;
|
||||
|
||||
yy = u8g2->width;
|
||||
yy -= x;
|
||||
|
||||
if ( dir == 0 )
|
||||
{
|
||||
yy--;
|
||||
yy -= len;
|
||||
yy++;
|
||||
dir = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
yy--;
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
|
||||
u8g2_draw_hv_line_2dir(u8g2, xx, yy, len, dir);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*============================================*/
|
||||
const u8g2_cb_t u8g2_cb_r0 = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_l90_r0 };
|
||||
const u8g2_cb_t u8g2_cb_r1 = { u8g2_update_dimension_r1, u8g2_update_page_win_r1, u8g2_draw_l90_r1 };
|
||||
const u8g2_cb_t u8g2_cb_r2 = { u8g2_update_dimension_r2, u8g2_update_page_win_r2, u8g2_draw_l90_r2 };
|
||||
const u8g2_cb_t u8g2_cb_r3 = { u8g2_update_dimension_r3, u8g2_update_page_win_r3, u8g2_draw_l90_r3 };
|
||||
|
||||
const u8g2_cb_t u8g2_cb_mirror = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_l90_mirrorr_r0 };
|
||||
const u8g2_cb_t u8g2_cb_mirror_vertical = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_mirror_vertical_r0 };
|
||||
|
||||
/*============================================*/
|
||||
/* setup for the null device */
|
||||
|
||||
/* setup for the null (empty) device */
|
||||
void u8g2_Setup_null(u8g2_t *u8g2, const u8g2_cb_t *rotation, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
|
||||
{
|
||||
static uint8_t buf[8];
|
||||
u8g2_SetupDisplay(u8g2, u8x8_d_null_cb, u8x8_cad_empty, byte_cb, gpio_and_delay_cb);
|
||||
u8g2_SetupBuffer(u8g2, buf, 1, u8g2_ll_hvline_vertical_top_lsb, rotation);
|
||||
}
|
||||
|
||||
|
||||
|
||||
260
Middlewares/u8g2Lib/src/u8log.c
Normal file
260
Middlewares/u8g2Lib/src/u8log.c
Normal file
@ -0,0 +1,260 @@
|
||||
/*
|
||||
|
||||
u8log.c
|
||||
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2018, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "u8x8.h"
|
||||
|
||||
|
||||
/*
|
||||
static uint8_t u8log_is_on_screen(u8log_t *u8log, uint8_t x, uint8_t y)
|
||||
{
|
||||
if ( x >= u8log->width )
|
||||
return 0;
|
||||
if ( y >= u8log->height )
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
static void u8log_clear_screen(u8log_t *u8log)
|
||||
{
|
||||
uint8_t *dest = u8log->screen_buffer;
|
||||
uint16_t cnt = u8log->height;
|
||||
cnt *= u8log->width;
|
||||
do
|
||||
{
|
||||
*dest++ = ' ';
|
||||
cnt--;
|
||||
} while( cnt > 0 );
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* scroll the content of the complete buffer, set redraw_line to 255 */
|
||||
static void u8log_scroll_up(u8log_t *u8log)
|
||||
{
|
||||
uint8_t *dest = u8log->screen_buffer;
|
||||
uint8_t *src = dest+u8log->width;
|
||||
uint16_t cnt = u8log->height;
|
||||
cnt--;
|
||||
cnt *= u8log->width;
|
||||
do
|
||||
{
|
||||
*dest++ = *src++;
|
||||
cnt--;
|
||||
} while( cnt > 0 );
|
||||
cnt = u8log->width;
|
||||
do
|
||||
{
|
||||
*dest++ = ' ';
|
||||
cnt--;
|
||||
} while(cnt > 0);
|
||||
|
||||
if ( u8log->is_redraw_line_for_each_char )
|
||||
u8log->is_redraw_all = 1;
|
||||
else
|
||||
u8log->is_redraw_all_required_for_next_nl = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
Place the cursor on the screen. This will also scroll, if required
|
||||
*/
|
||||
static void u8log_cursor_on_screen(u8log_t *u8log)
|
||||
{
|
||||
//printf("u8log_cursor_on_screen, cursor_y=%d\n", u8log->cursor_y);
|
||||
if ( u8log->cursor_x >= u8log->width )
|
||||
{
|
||||
u8log->cursor_x = 0;
|
||||
u8log->cursor_y++;
|
||||
}
|
||||
while ( u8log->cursor_y >= u8log->height )
|
||||
{
|
||||
u8log_scroll_up(u8log);
|
||||
u8log->cursor_y--;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Write a printable, single char on the screen, do any kind of scrolling
|
||||
*/
|
||||
static void u8log_write_to_screen(u8log_t *u8log, uint8_t c)
|
||||
{
|
||||
u8log_cursor_on_screen(u8log);
|
||||
u8log->screen_buffer[u8log->cursor_y * u8log->width + u8log->cursor_x] = c;
|
||||
u8log->cursor_x++;
|
||||
|
||||
if ( u8log->is_redraw_line_for_each_char )
|
||||
{
|
||||
u8log->is_redraw_line = 1;
|
||||
u8log->redraw_line = u8log->cursor_y;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Handle control codes or write the char to the screen.
|
||||
Supported control codes are:
|
||||
|
||||
\n 10 Goto first position of the next line. Line is marked for redraw.
|
||||
\r 13 Goto first position in the same line. Line is marked for redraw.
|
||||
\t 9 Jump to the next tab position
|
||||
\f 12 Clear the screen and mark redraw for whole screen
|
||||
any other char Write char to screen. Line redraw mark depends on
|
||||
is_redraw_line_for_each_char flag.
|
||||
*/
|
||||
void u8log_write_char(u8log_t *u8log, uint8_t c)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case '\n': // 10
|
||||
u8log->is_redraw_line = 1;
|
||||
u8log->redraw_line = u8log->cursor_y;
|
||||
if ( u8log->is_redraw_all_required_for_next_nl )
|
||||
u8log->is_redraw_all = 1;
|
||||
u8log->is_redraw_all_required_for_next_nl = 0;
|
||||
u8log->cursor_y++;
|
||||
u8log->cursor_x = 0;
|
||||
break;
|
||||
case '\r': // 13
|
||||
u8log->is_redraw_line = 1;
|
||||
u8log->redraw_line = u8log->cursor_y;
|
||||
u8log->cursor_x = 0;
|
||||
break;
|
||||
case '\t': // 9
|
||||
u8log->cursor_x = (u8log->cursor_x + 8) & 0xf8;
|
||||
break;
|
||||
case '\f': // 12
|
||||
u8log_clear_screen(u8log);
|
||||
u8log->is_redraw_all = 1;
|
||||
u8log->cursor_x = 0;
|
||||
u8log->cursor_y = 0;
|
||||
break;
|
||||
default:
|
||||
u8log_write_to_screen(u8log, c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void u8log_Init(u8log_t *u8log, uint8_t width, uint8_t height, uint8_t *buf)
|
||||
{
|
||||
memset(u8log, 0, sizeof(u8log_t));
|
||||
u8log->width = width;
|
||||
u8log->height = height;
|
||||
u8log->screen_buffer = buf;
|
||||
u8log_clear_screen(u8log);
|
||||
}
|
||||
|
||||
void u8log_SetCallback(u8log_t *u8log, u8log_cb cb, void *aux_data)
|
||||
{
|
||||
u8log->cb = cb;
|
||||
u8log->aux_data = aux_data;
|
||||
}
|
||||
|
||||
void u8log_SetRedrawMode(u8log_t *u8log, uint8_t is_redraw_line_for_each_char)
|
||||
{
|
||||
u8log->is_redraw_line_for_each_char = is_redraw_line_for_each_char;
|
||||
}
|
||||
|
||||
/* offset can be negative or positive, it is 0 by default */
|
||||
void u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset)
|
||||
{
|
||||
u8log->line_height_offset = line_height_offset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void u8log_WriteChar(u8log_t *u8log, uint8_t c)
|
||||
{
|
||||
u8log_write_char(u8log, c);
|
||||
if ( u8log->is_redraw_line || u8log->is_redraw_all )
|
||||
{
|
||||
if ( u8log->cb != 0 )
|
||||
{
|
||||
u8log->cb(u8log);
|
||||
}
|
||||
u8log->is_redraw_line = 0;
|
||||
u8log->is_redraw_all = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void u8log_WriteString(u8log_t *u8log, const char *s)
|
||||
{
|
||||
while( *s != '\0' )
|
||||
{
|
||||
u8log_WriteChar(u8log, *s);
|
||||
s++;
|
||||
}
|
||||
}
|
||||
|
||||
static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b) U8X8_NOINLINE;
|
||||
static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b)
|
||||
{
|
||||
b &= 0x0f;
|
||||
if ( b < 10 )
|
||||
u8log_WriteChar(u8log, b+'0');
|
||||
else
|
||||
u8log_WriteChar(u8log, b+'a'-10);
|
||||
}
|
||||
|
||||
void u8log_WriteHex8(u8log_t *u8log, uint8_t b)
|
||||
{
|
||||
u8log_WriteHexHalfByte(u8log, b >> 4);
|
||||
u8log_WriteHexHalfByte(u8log, b);
|
||||
}
|
||||
|
||||
void u8log_WriteHex16(u8log_t *u8log, uint16_t v)
|
||||
{
|
||||
u8log_WriteHex8(u8log, v>>8);
|
||||
u8log_WriteHex8(u8log, v);
|
||||
}
|
||||
|
||||
void u8log_WriteHex32(u8log_t *u8log, uint32_t v)
|
||||
{
|
||||
u8log_WriteHex16(u8log, v>>16);
|
||||
u8log_WriteHex16(u8log, v);
|
||||
}
|
||||
|
||||
/* v = value, d = number of digits (1..3) */
|
||||
void u8log_WriteDec8(u8log_t *u8log, uint8_t v, uint8_t d)
|
||||
{
|
||||
u8log_WriteString(u8log, u8x8_u8toa(v, d));
|
||||
}
|
||||
|
||||
/* v = value, d = number of digits (1..5) */
|
||||
void u8log_WriteDec16(u8log_t *u8log, uint16_t v, uint8_t d)
|
||||
{
|
||||
u8log_WriteString(u8log, u8x8_u16toa(v, d));
|
||||
}
|
||||
98
Middlewares/u8g2Lib/src/u8log_u8g2.c
Normal file
98
Middlewares/u8g2Lib/src/u8log_u8g2.c
Normal file
@ -0,0 +1,98 @@
|
||||
/*
|
||||
|
||||
u8log_u8g2.c
|
||||
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2018, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8g2.h"
|
||||
/*
|
||||
Draw the u8log text at the specified x/y position.
|
||||
x/y position is the reference position of the first char of the first line.
|
||||
the line height is
|
||||
u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2) + line_height_offset;
|
||||
line_height_offset can be set with u8log_SetLineHeightOffset()
|
||||
Use
|
||||
u8g2_SetFontRefHeightText(u8g2_t *u8g2);
|
||||
u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
|
||||
u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
|
||||
to change the return values for u8g2_GetAscent and u8g2_GetDescent
|
||||
|
||||
*/
|
||||
void u8g2_DrawLog(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8log_t *u8log)
|
||||
{
|
||||
u8g2_uint_t disp_x, disp_y;
|
||||
uint8_t buf_x, buf_y;
|
||||
uint8_t c;
|
||||
|
||||
disp_y = y;
|
||||
u8g2_SetFontDirection(u8g2, 0);
|
||||
for( buf_y = 0; buf_y < u8log->height; buf_y++ )
|
||||
{
|
||||
disp_x = x;
|
||||
for( buf_x = 0; buf_x < u8log->width; buf_x++ )
|
||||
{
|
||||
c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
|
||||
disp_x += u8g2_DrawGlyph(u8g2, disp_x, disp_y, c);
|
||||
}
|
||||
disp_y += u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2);
|
||||
disp_y += u8log->line_height_offset;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
u8lib callback for u8g2
|
||||
|
||||
Only font direction 0 is supported: u8g2_SetFontDirection(u8g2, 0)
|
||||
Use
|
||||
u8g2_SetFontRefHeightText(u8g2_t *u8g2);
|
||||
u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
|
||||
u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
|
||||
to change the top offset and the line height and
|
||||
u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset)
|
||||
to change the line height.
|
||||
|
||||
*/
|
||||
void u8log_u8g2_cb(u8log_t * u8log)
|
||||
{
|
||||
u8g2_t *u8g2 = (u8g2_t *)(u8log->aux_data);
|
||||
if ( u8log->is_redraw_line || u8log->is_redraw_all )
|
||||
{
|
||||
u8g2_FirstPage(u8g2);
|
||||
do
|
||||
{
|
||||
u8g2_DrawLog( u8g2, 0, u8g2_GetAscent(u8g2), u8log);
|
||||
}
|
||||
while( u8g2_NextPage(u8g2) );
|
||||
}
|
||||
}
|
||||
|
||||
75
Middlewares/u8g2Lib/src/u8log_u8x8.c
Normal file
75
Middlewares/u8g2Lib/src/u8log_u8x8.c
Normal file
@ -0,0 +1,75 @@
|
||||
/*
|
||||
|
||||
u8log_u8x8.c
|
||||
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2018, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log) U8X8_NOINLINE;
|
||||
static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log)
|
||||
{
|
||||
uint8_t buf_x;
|
||||
uint8_t c;
|
||||
for( buf_x = 0; buf_x < u8log->width; buf_x++ )
|
||||
{
|
||||
c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
|
||||
u8x8_DrawGlyph(u8x8, disp_x, disp_y, c);
|
||||
disp_x++;
|
||||
}
|
||||
}
|
||||
|
||||
void u8x8_DrawLog(u8x8_t *u8x8, uint8_t x, uint8_t y, u8log_t *u8log)
|
||||
{
|
||||
uint8_t buf_y;
|
||||
for( buf_y = 0; buf_y < u8log->height; buf_y++ )
|
||||
{
|
||||
u8x8_DrawLogLine(u8x8, x, y, buf_y, u8log);
|
||||
y++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void u8log_u8x8_cb(u8log_t * u8log)
|
||||
{
|
||||
u8x8_t *u8x8 = (u8x8_t *)(u8log->aux_data);
|
||||
if ( u8log->is_redraw_all )
|
||||
{
|
||||
u8x8_DrawLog(u8x8, 0, 0, u8log);
|
||||
}
|
||||
else if ( u8log->is_redraw_line )
|
||||
{
|
||||
u8x8_DrawLogLine(u8x8, 0, u8log->redraw_line, u8log->redraw_line, u8log);
|
||||
}
|
||||
}
|
||||
|
||||
493
Middlewares/u8g2Lib/src/u8x8_8x8.c
Normal file
493
Middlewares/u8g2Lib/src/u8x8_8x8.c
Normal file
@ -0,0 +1,493 @@
|
||||
/*
|
||||
|
||||
u8x8_8x8.c
|
||||
|
||||
font procedures, directly interfaces display procedures
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
#if defined(ESP8266)
|
||||
uint8_t u8x8_pgm_read_esp(const uint8_t * addr)
|
||||
{
|
||||
uint32_t bytes;
|
||||
bytes = *(uint32_t*)((uint32_t)addr & ~3);
|
||||
return ((uint8_t*)&bytes)[(uint32_t)addr & 3];
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void u8x8_SetFont(u8x8_t *u8x8, const uint8_t *font_8x8)
|
||||
{
|
||||
u8x8->font = font_8x8;
|
||||
}
|
||||
|
||||
/*
|
||||
Args:
|
||||
u8x8: ptr to u8x8 structure
|
||||
encoding: glyph for which the data is requested (must be between 0 and 255)
|
||||
buf: pointer to 8 bytes
|
||||
*/
|
||||
static void u8x8_get_glyph_data(u8x8_t *u8x8, uint8_t encoding, uint8_t *buf, uint8_t tile_offset) U8X8_NOINLINE;
|
||||
static void u8x8_get_glyph_data(u8x8_t *u8x8, uint8_t encoding, uint8_t *buf, uint8_t tile_offset)
|
||||
{
|
||||
uint8_t first, last, tiles, i;
|
||||
uint16_t offset;
|
||||
first = u8x8_pgm_read(u8x8->font+0);
|
||||
last = u8x8_pgm_read(u8x8->font+1);
|
||||
tiles = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
tiles *= u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
|
||||
/* get the glyph bitmap from the font */
|
||||
if ( first <= encoding && encoding <= last )
|
||||
{
|
||||
offset = encoding;
|
||||
offset -= first;
|
||||
offset *= tiles; /* new 2019 format */
|
||||
offset += tile_offset; /* new 2019 format */
|
||||
offset *= 8;
|
||||
offset +=4; /* changed from 2 to 4, new 2019 format */
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
buf[i] = u8x8_pgm_read(u8x8->font+offset);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
buf[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* invert the bitmap if required */
|
||||
if ( u8x8->is_font_inverse_mode )
|
||||
{
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
buf[i] ^= 255;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void u8x8_DrawGlyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
|
||||
{
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
uint8_t tv = u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
uint8_t xx, tile;
|
||||
uint8_t buf[8];
|
||||
th += x;
|
||||
tv += y;
|
||||
tile = 0;
|
||||
do
|
||||
{
|
||||
xx = x;
|
||||
do
|
||||
{
|
||||
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
|
||||
u8x8_DrawTile(u8x8, xx, y, 1, buf);
|
||||
tile++;
|
||||
xx++;
|
||||
} while( xx < th );
|
||||
y++;
|
||||
} while( y < tv );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Source: http://graphics.stanford.edu/~seander/bithacks.html
|
||||
Section: Interleave bits by Binary Magic Numbers
|
||||
Original codes is here:
|
||||
static const unsigned int B[] = {0x55555555, 0x33333333, 0x0F0F0F0F, 0x00FF00FF};
|
||||
static const unsigned int S[] = {1, 2, 4, 8};
|
||||
|
||||
unsigned int x; // Interleave lower 16 bits of x and y, so the bits of x
|
||||
unsigned int y; // are in the even positions and bits from y in the odd;
|
||||
unsigned int z; // z gets the resulting 32-bit Morton Number.
|
||||
// x and y must initially be less than 65536.
|
||||
|
||||
x = (x | (x << S[3])) & B[3];
|
||||
x = (x | (x << S[2])) & B[2];
|
||||
x = (x | (x << S[1])) & B[1];
|
||||
x = (x | (x << S[0])) & B[0];
|
||||
|
||||
y = (y | (y << S[3])) & B[3];
|
||||
y = (y | (y << S[2])) & B[2];
|
||||
y = (y | (y << S[1])) & B[1];
|
||||
y = (y | (y << S[0])) & B[0];
|
||||
|
||||
z = x | (y << 1);
|
||||
*/
|
||||
uint16_t u8x8_upscale_byte(uint8_t x)
|
||||
{
|
||||
uint16_t y = x;
|
||||
y |= (y << 4); // x = (x | (x << S[2])) & B[2];
|
||||
y &= 0x0f0f;
|
||||
y |= (y << 2); // x = (x | (x << S[1])) & B[1];
|
||||
y &= 0x3333;
|
||||
y |= (y << 1); // x = (x | (x << S[0])) & B[0];
|
||||
y &= 0x5555;
|
||||
|
||||
y |= (y << 1); // z = x | (y << 1);
|
||||
return y;
|
||||
}
|
||||
|
||||
static void u8x8_upscale_buf(uint8_t *src, uint8_t *dest) U8X8_NOINLINE;
|
||||
static void u8x8_upscale_buf(uint8_t *src, uint8_t *dest)
|
||||
{
|
||||
uint8_t i = 4;
|
||||
do
|
||||
{
|
||||
*dest++ = *src;
|
||||
*dest++ = *src++;
|
||||
i--;
|
||||
} while( i > 0 );
|
||||
}
|
||||
|
||||
static void u8x8_draw_2x2_subglyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding, uint8_t tile)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t t;
|
||||
uint8_t buf[8];
|
||||
uint8_t buf1[8];
|
||||
uint8_t buf2[8];
|
||||
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
|
||||
for( i = 0; i < 8; i ++ )
|
||||
{
|
||||
t = u8x8_upscale_byte(buf[i]);
|
||||
buf1[i] = t >> 8;
|
||||
buf2[i] = t & 255;
|
||||
}
|
||||
u8x8_upscale_buf(buf2, buf);
|
||||
u8x8_DrawTile(u8x8, x, y, 1, buf);
|
||||
|
||||
u8x8_upscale_buf(buf2+4, buf);
|
||||
u8x8_DrawTile(u8x8, x+1, y, 1, buf);
|
||||
|
||||
u8x8_upscale_buf(buf1, buf);
|
||||
u8x8_DrawTile(u8x8, x, y+1, 1, buf);
|
||||
|
||||
u8x8_upscale_buf(buf1+4, buf);
|
||||
u8x8_DrawTile(u8x8, x+1, y+1, 1, buf);
|
||||
}
|
||||
|
||||
|
||||
void u8x8_Draw2x2Glyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
|
||||
{
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
uint8_t tv = u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
uint8_t xx, tile;
|
||||
th *= 2;
|
||||
th += x;
|
||||
tv *= 2;
|
||||
tv += y;
|
||||
tile = 0;
|
||||
do
|
||||
{
|
||||
xx = x;
|
||||
do
|
||||
{
|
||||
u8x8_draw_2x2_subglyph(u8x8, xx, y, encoding, tile);
|
||||
tile++;
|
||||
xx+=2;
|
||||
} while( xx < th );
|
||||
y+=2;
|
||||
} while( y < tv );
|
||||
}
|
||||
|
||||
/* https://github.com/olikraus/u8g2/issues/474 */
|
||||
static void u8x8_draw_1x2_subglyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding, uint8_t tile)
|
||||
{
|
||||
uint8_t i;
|
||||
uint16_t t;
|
||||
uint8_t buf[8];
|
||||
uint8_t buf1[8];
|
||||
uint8_t buf2[8];
|
||||
u8x8_get_glyph_data(u8x8, encoding, buf, tile);
|
||||
for( i = 0; i < 8; i ++ )
|
||||
{
|
||||
t = u8x8_upscale_byte(buf[i]);
|
||||
buf1[i] = t >> 8;
|
||||
buf2[i] = t & 255;
|
||||
}
|
||||
u8x8_DrawTile(u8x8, x, y, 1, buf2);
|
||||
u8x8_DrawTile(u8x8, x, y+1, 1, buf1);
|
||||
}
|
||||
|
||||
void u8x8_Draw1x2Glyph(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t encoding)
|
||||
{
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
uint8_t tv = u8x8_pgm_read(u8x8->font+3); /* new 2019 format */
|
||||
uint8_t xx, tile;
|
||||
th += x;
|
||||
tv *= 2;
|
||||
tv += y;
|
||||
tile = 0;
|
||||
do
|
||||
{
|
||||
xx = x;
|
||||
do
|
||||
{
|
||||
u8x8_draw_1x2_subglyph(u8x8, xx, y, encoding, tile);
|
||||
tile++;
|
||||
xx++;
|
||||
} while( xx < th );
|
||||
y+=2;
|
||||
} while( y < tv );
|
||||
}
|
||||
|
||||
/*
|
||||
source: https://en.wikipedia.org/wiki/UTF-8
|
||||
Bits from to bytes Byte 1 Byte 2 Byte 3 Byte 4 Byte 5 Byte 6
|
||||
7 U+0000 U+007F 1 0xxxxxxx
|
||||
11 U+0080 U+07FF 2 110xxxxx 10xxxxxx
|
||||
16 U+0800 U+FFFF 3 1110xxxx 10xxxxxx 10xxxxxx
|
||||
21 U+10000 U+1FFFFF 4 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
26 U+200000 U+3FFFFFF 5 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
31 U+4000000 U+7FFFFFFF 6 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
|
||||
|
||||
*/
|
||||
|
||||
/* reset the internal state machine */
|
||||
void u8x8_utf8_init(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->utf8_state = 0; /* also reset during u8x8_SetupDefaults() */
|
||||
}
|
||||
|
||||
uint16_t u8x8_ascii_next(U8X8_UNUSED u8x8_t *u8x8, uint8_t b)
|
||||
{
|
||||
if ( b == 0 || b == '\n' ) /* '\n' terminates the string to support the string list procedures */
|
||||
return 0x0ffff; /* end of string detected*/
|
||||
return b;
|
||||
}
|
||||
|
||||
/*
|
||||
pass a byte from an utf8 encoded string to the utf8 decoder state machine
|
||||
returns
|
||||
0x0fffe: no glyph, just continue
|
||||
0x0ffff: end of string
|
||||
anything else: The decoded encoding
|
||||
*/
|
||||
uint16_t u8x8_utf8_next(u8x8_t *u8x8, uint8_t b)
|
||||
{
|
||||
if ( b == 0 || b == '\n' ) /* '\n' terminates the string to support the string list procedures */
|
||||
return 0x0ffff; /* end of string detected, pending UTF8 is discarded */
|
||||
if ( u8x8->utf8_state == 0 )
|
||||
{
|
||||
if ( b >= 0xfc ) /* 6 byte sequence */
|
||||
{
|
||||
u8x8->utf8_state = 5;
|
||||
b &= 1;
|
||||
}
|
||||
else if ( b >= 0xf8 )
|
||||
{
|
||||
u8x8->utf8_state = 4;
|
||||
b &= 3;
|
||||
}
|
||||
else if ( b >= 0xf0 )
|
||||
{
|
||||
u8x8->utf8_state = 3;
|
||||
b &= 7;
|
||||
}
|
||||
else if ( b >= 0xe0 )
|
||||
{
|
||||
u8x8->utf8_state = 2;
|
||||
b &= 15;
|
||||
}
|
||||
else if ( b >= 0xc0 )
|
||||
{
|
||||
u8x8->utf8_state = 1;
|
||||
b &= 0x01f;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* do nothing, just use the value as encoding */
|
||||
return b;
|
||||
}
|
||||
u8x8->encoding = b;
|
||||
return 0x0fffe;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8x8->utf8_state--;
|
||||
/* The case b < 0x080 (an illegal UTF8 encoding) is not checked here. */
|
||||
u8x8->encoding<<=6;
|
||||
b &= 0x03f;
|
||||
u8x8->encoding |= b;
|
||||
if ( u8x8->utf8_state != 0 )
|
||||
return 0x0fffe; /* nothing to do yet */
|
||||
}
|
||||
return u8x8->encoding;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t u8x8_draw_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s) U8X8_NOINLINE;
|
||||
static uint8_t u8x8_draw_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8->next_cb(u8x8, (uint8_t)*s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
u8x8_DrawGlyph(u8x8, x, y, e);
|
||||
x+=th;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_DrawString(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_ascii_next;
|
||||
return u8x8_draw_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
uint8_t u8x8_DrawUTF8(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_utf8_next;
|
||||
return u8x8_draw_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t u8x8_draw_2x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s) U8X8_NOINLINE;
|
||||
static uint8_t u8x8_draw_2x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
|
||||
th <<= 1;
|
||||
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8->next_cb(u8x8, (uint8_t)*s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
u8x8_Draw2x2Glyph(u8x8, x, y, e);
|
||||
x+=th;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_Draw2x2String(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_ascii_next;
|
||||
return u8x8_draw_2x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
uint8_t u8x8_Draw2x2UTF8(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_utf8_next;
|
||||
return u8x8_draw_2x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static uint8_t u8x8_draw_1x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s) U8X8_NOINLINE;
|
||||
static uint8_t u8x8_draw_1x2_string(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
uint8_t th = u8x8_pgm_read(u8x8->font+2); /* new 2019 format */
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8->next_cb(u8x8, (uint8_t)*s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
{
|
||||
u8x8_Draw1x2Glyph(u8x8, x, y, e);
|
||||
x+=th;
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_Draw1x2String(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_ascii_next;
|
||||
return u8x8_draw_1x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
uint8_t u8x8_Draw1x2UTF8(u8x8_t *u8x8, uint8_t x, uint8_t y, const char *s)
|
||||
{
|
||||
u8x8->next_cb = u8x8_utf8_next;
|
||||
return u8x8_draw_1x2_string(u8x8, x, y, s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t u8x8_GetUTF8Len(u8x8_t *u8x8, const char *s)
|
||||
{
|
||||
uint16_t e;
|
||||
uint8_t cnt = 0;
|
||||
u8x8_utf8_init(u8x8);
|
||||
for(;;)
|
||||
{
|
||||
e = u8x8_utf8_next(u8x8, *s);
|
||||
if ( e == 0x0ffff )
|
||||
break;
|
||||
s++;
|
||||
if ( e != 0x0fffe )
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
||||
666
Middlewares/u8g2Lib/src/u8x8_byte.c
Normal file
666
Middlewares/u8g2Lib/src/u8x8_byte.c
Normal file
@ -0,0 +1,666 @@
|
||||
/*
|
||||
|
||||
u8x8_byte.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
uint8_t u8x8_byte_SetDC(u8x8_t *u8x8, uint8_t dc)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_SET_DC, dc, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_SendBytes(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_SEND, cnt, (void *)data);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_SendByte(u8x8_t *u8x8, uint8_t byte)
|
||||
{
|
||||
return u8x8_byte_SendBytes(u8x8, 1, &byte);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_StartTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_START_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_EndTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->byte_cb(u8x8, U8X8_MSG_BYTE_END_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
uint8_t u8x8_byte_empty(U8X8_UNUSED u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
break; /* do nothing */
|
||||
}
|
||||
return 1; /* always succeed */
|
||||
}
|
||||
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
|
||||
/*
|
||||
Uses:
|
||||
u8x8->display_info->sda_setup_time_ns
|
||||
u8x8->display_info->sck_pulse_width_ns
|
||||
u8x8->display_info->spi_mode
|
||||
u8x8->display_info->chip_disable_level
|
||||
u8x8->display_info->chip_enable_level
|
||||
u8x8->display_info->post_chip_enable_wait_ns
|
||||
u8x8->display_info->pre_chip_disable_wait_ns
|
||||
Calls to GPIO and DELAY:
|
||||
U8X8_MSG_DELAY_NANO
|
||||
U8X8_MSG_GPIO_DC
|
||||
U8X8_MSG_GPIO_CS
|
||||
U8X8_MSG_GPIO_CLOCK
|
||||
U8X8_MSG_GPIO_DATA
|
||||
Handles:
|
||||
U8X8_MSG_BYTE_INIT
|
||||
U8X8_MSG_BYTE_SEND
|
||||
U8X8_MSG_BYTE_SET_DC
|
||||
U8X8_MSG_BYTE_START_TRANSFER
|
||||
U8X8_MSG_BYTE_END_TRANSFER
|
||||
*/
|
||||
|
||||
uint8_t u8x8_byte_4wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
uint8_t takeover_edge = u8x8_GetSPIClockPhase(u8x8);
|
||||
uint8_t not_takeover_edge = 1 - takeover_edge;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = 0; i < 8; i++ )
|
||||
{
|
||||
if ( b & 128 )
|
||||
u8x8_gpio_SetSPIData(u8x8, 1);
|
||||
else
|
||||
u8x8_gpio_SetSPIData(u8x8, 0);
|
||||
b <<= 1;
|
||||
|
||||
u8x8_gpio_SetSPIClock(u8x8, not_takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sda_setup_time_ns);
|
||||
u8x8_gpio_SetSPIClock(u8x8, takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sck_pulse_width_ns);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* no wait required here */
|
||||
|
||||
/* for SPI: setup correct level of the clock signal */
|
||||
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSPIClockPhase(u8x8));
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
uint8_t u8x8_byte_8bit_6800mode(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signal is high */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_8bit_8080mode(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signal is high */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
uint8_t u8x8_byte_3wire_sw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t *data;
|
||||
uint8_t takeover_edge = u8x8_GetSPIClockPhase(u8x8);
|
||||
uint8_t not_takeover_edge = 1 - takeover_edge;
|
||||
uint16_t b;
|
||||
static uint8_t last_dc;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
if ( last_dc != 0 )
|
||||
b |= 256;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = 0; i < 9; i++ )
|
||||
{
|
||||
if ( b & 256 )
|
||||
u8x8_gpio_SetSPIData(u8x8, 1);
|
||||
else
|
||||
u8x8_gpio_SetSPIData(u8x8, 0);
|
||||
b <<= 1;
|
||||
|
||||
u8x8_gpio_SetSPIClock(u8x8, not_takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sda_setup_time_ns);
|
||||
u8x8_gpio_SetSPIClock(u8x8, takeover_edge);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->sck_pulse_width_ns);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* no wait required here */
|
||||
|
||||
/* for SPI: setup correct level of the clock signal */
|
||||
u8x8_gpio_SetSPIClock(u8x8, u8x8_GetSPIClockPhase(u8x8));
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
last_dc = arg_int;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_enable_level);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
void u8x8_byte_set_ks0108_cs(u8x8_t *u8x8, uint8_t arg)
|
||||
{
|
||||
u8x8_gpio_SetCS(u8x8, arg&1);
|
||||
arg = arg >> 1;
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS1, arg&1);
|
||||
arg = arg >> 1;
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS2, arg&1);
|
||||
}
|
||||
|
||||
/* 6800 mode */
|
||||
uint8_t u8x8_byte_ks0108(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signal is low */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
/* expects 3 bits in arg_int for the chip select lines */
|
||||
u8x8_byte_set_ks0108_cs(u8x8, arg_int);
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->post_chip_enable_wait_ns, NULL);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->pre_chip_disable_wait_ns, NULL);
|
||||
u8x8_byte_set_ks0108_cs(u8x8, arg_int);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* sed1520 or sbn1661
|
||||
U8X8_MSG_GPIO_E --> E1
|
||||
U8X8_MSG_GPIO_CS --> E2
|
||||
*/
|
||||
uint8_t u8x8_byte_sed1520(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i, b;
|
||||
uint8_t *data;
|
||||
static uint8_t enable_pin;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
for( i = U8X8_MSG_GPIO_D0; i <= U8X8_MSG_GPIO_D7; i++ )
|
||||
{
|
||||
u8x8_gpio_call(u8x8, i, b&1);
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->data_setup_time_ns);
|
||||
u8x8_gpio_call(u8x8, enable_pin, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 200); /* KS0108 requires 450 ns, use 200 here */
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, u8x8->display_info->write_pulse_width_ns); /* expect 250 here */
|
||||
u8x8_gpio_call(u8x8, enable_pin, 0);
|
||||
}
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
/* disable chipselect */
|
||||
u8x8_gpio_SetCS(u8x8, u8x8->display_info->chip_disable_level);
|
||||
/* ensure that the enable signals are low */
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_E, 0);
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO_CS, 0);
|
||||
enable_pin = U8X8_MSG_GPIO_E;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
u8x8_gpio_SetDC(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
/* cs lines are not supported for the SED1520/SBN1661 */
|
||||
/* instead, this will select the E1 or E2 line */
|
||||
enable_pin = U8X8_MSG_GPIO_E;
|
||||
if ( arg_int != 0 )
|
||||
enable_pin = U8X8_MSG_GPIO_CS;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
|
||||
/*
|
||||
software i2c,
|
||||
ignores ACK response (which is anyway not provided by some displays)
|
||||
also does not allow reading from the device
|
||||
*/
|
||||
static void i2c_delay(u8x8_t *u8x8) U8X8_NOINLINE;
|
||||
static void i2c_delay(u8x8_t *u8x8)
|
||||
{
|
||||
//u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_10MICRO, u8x8->display_info->i2c_bus_clock_100kHz);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_I2C, u8x8->display_info->i2c_bus_clock_100kHz);
|
||||
}
|
||||
|
||||
static void i2c_init(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8_gpio_SetI2CClock(u8x8, 1);
|
||||
u8x8_gpio_SetI2CData(u8x8, 1);
|
||||
|
||||
i2c_delay(u8x8);
|
||||
}
|
||||
|
||||
/* actually, the scl line is not observed, so this procedure does not return a value */
|
||||
|
||||
static void i2c_read_scl_and_delay(u8x8_t *u8x8)
|
||||
{
|
||||
/* set as input (line will be high) */
|
||||
u8x8_gpio_SetI2CClock(u8x8, 1);
|
||||
|
||||
i2c_delay(u8x8);
|
||||
}
|
||||
|
||||
static void i2c_clear_scl(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8_gpio_SetI2CClock(u8x8, 0);
|
||||
}
|
||||
|
||||
static void i2c_read_sda(u8x8_t *u8x8)
|
||||
{
|
||||
/* set as input (line will be high) */
|
||||
u8x8_gpio_SetI2CData(u8x8, 1);
|
||||
}
|
||||
|
||||
static void i2c_clear_sda(u8x8_t *u8x8)
|
||||
{
|
||||
/* set open collector and drive low */
|
||||
u8x8_gpio_SetI2CData(u8x8, 0);
|
||||
}
|
||||
|
||||
static void i2c_start(u8x8_t *u8x8)
|
||||
{
|
||||
if ( u8x8->i2c_started != 0 )
|
||||
{
|
||||
/* if already started: do restart */
|
||||
i2c_read_sda(u8x8); /* SDA = 1 */
|
||||
i2c_delay(u8x8);
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
}
|
||||
i2c_read_sda(u8x8);
|
||||
/* send the start condition, both lines go from 1 to 0 */
|
||||
i2c_clear_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
i2c_clear_scl(u8x8);
|
||||
u8x8->i2c_started = 1;
|
||||
}
|
||||
|
||||
|
||||
static void i2c_stop(u8x8_t *u8x8)
|
||||
{
|
||||
/* set SDA to 0 */
|
||||
i2c_clear_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
|
||||
/* now release all lines */
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
|
||||
/* set SDA to 1 */
|
||||
i2c_read_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
u8x8->i2c_started = 0;
|
||||
}
|
||||
|
||||
static void i2c_write_bit(u8x8_t *u8x8, uint8_t val)
|
||||
{
|
||||
if (val)
|
||||
i2c_read_sda(u8x8);
|
||||
else
|
||||
i2c_clear_sda(u8x8);
|
||||
|
||||
i2c_delay(u8x8);
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
i2c_clear_scl(u8x8);
|
||||
}
|
||||
|
||||
static void i2c_read_bit(u8x8_t *u8x8)
|
||||
{
|
||||
//uint8_t val;
|
||||
/* do not drive SDA */
|
||||
i2c_read_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
i2c_read_scl_and_delay(u8x8);
|
||||
i2c_read_sda(u8x8);
|
||||
i2c_delay(u8x8);
|
||||
i2c_clear_scl(u8x8);
|
||||
//return val;
|
||||
}
|
||||
|
||||
static void i2c_write_byte(u8x8_t *u8x8, uint8_t b)
|
||||
{
|
||||
i2c_write_bit(u8x8, b & 128);
|
||||
i2c_write_bit(u8x8, b & 64);
|
||||
i2c_write_bit(u8x8, b & 32);
|
||||
i2c_write_bit(u8x8, b & 16);
|
||||
i2c_write_bit(u8x8, b & 8);
|
||||
i2c_write_bit(u8x8, b & 4);
|
||||
i2c_write_bit(u8x8, b & 2);
|
||||
i2c_write_bit(u8x8, b & 1);
|
||||
|
||||
/* read ack from client */
|
||||
/* 0: ack was given by client */
|
||||
/* 1: nothing happend during ack cycle */
|
||||
i2c_read_bit(u8x8);
|
||||
}
|
||||
|
||||
uint8_t u8x8_byte_sw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
i2c_write_byte(u8x8, *data);
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
i2c_init(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
i2c_start(u8x8);
|
||||
i2c_write_byte(u8x8, u8x8_GetI2CAddress(u8x8));
|
||||
//i2c_write_byte(u8x8, 0x078);
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
i2c_stop(u8x8);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*=========================================*/
|
||||
|
||||
/* alternative i2c byte procedure */
|
||||
#ifdef ALTERNATIVE_I2C_BYTE_PROCEDURE
|
||||
|
||||
|
||||
void i2c_transfer(u8x8_t *u8x8, uint8_t adr, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
uint8_t i;
|
||||
i2c_start(u8x8);
|
||||
i2c_write_byte(u8x8, adr);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
i2c_write_byte(u8x8, data[i]);
|
||||
i2c_stop(u8x8);
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_byte_sw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t buffer[32]; /* u8g2/u8x8 will never send more than 32 bytes */
|
||||
static uint8_t buf_idx;
|
||||
uint8_t *data;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_BYTE_SEND:
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
buffer[buf_idx++] = *data;
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
break;
|
||||
case U8X8_MSG_BYTE_INIT:
|
||||
i2c_init(u8x8); /* init i2c communication */
|
||||
break;
|
||||
case U8X8_MSG_BYTE_SET_DC:
|
||||
/* ignored for i2c */
|
||||
break;
|
||||
case U8X8_MSG_BYTE_START_TRANSFER:
|
||||
buf_idx = 0;
|
||||
break;
|
||||
case U8X8_MSG_BYTE_END_TRANSFER:
|
||||
i2c_transfer(u8x8, u8x8_GetI2CAddress(u8x8), buf_idx, buffer);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
904
Middlewares/u8g2Lib/src/u8x8_cad.c
Normal file
904
Middlewares/u8g2Lib/src/u8x8_cad.c
Normal file
@ -0,0 +1,904 @@
|
||||
/*
|
||||
|
||||
u8x8_cad.c
|
||||
|
||||
"command arg data" interface to the graphics controller
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
The following sequence must be used for any data, which is set to the display:
|
||||
|
||||
|
||||
uint8_t u8x8_cad_StartTransfer(u8x8_t *u8x8)
|
||||
|
||||
any of the following calls
|
||||
uint8_t u8x8_cad_SendCmd(u8x8_t *u8x8, uint8_t cmd)
|
||||
uint8_t u8x8_cad_SendArg(u8x8_t *u8x8, uint8_t arg)
|
||||
uint8_t u8x8_cad_SendData(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
|
||||
|
||||
uint8_t u8x8_cad_EndTransfer(u8x8_t *u8x8)
|
||||
|
||||
|
||||
|
||||
*/
|
||||
/*
|
||||
uint8_t u8x8_cad_template(u8x8_t *u8x8, uint8_t msg, uint16_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_mcd_byte_SetDC(mcd->next, 1);
|
||||
u8x8_mcd_byte_Send(mcd->next, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_mcd_byte_SetDC(mcd->next, 1);
|
||||
u8x8_mcd_byte_Send(mcd->next, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_mcd_byte_SetDC(mcd->next, 0);
|
||||
for( i = 0; i < 8; i++ )
|
||||
u8x8_mcd_byte_Send(mcd->next, ((uint8_t *)arg_ptr)[i]);
|
||||
break;
|
||||
case U8X8_MSG_CAD_RESET:
|
||||
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return mcd->next->cb(mcd->next, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
uint8_t u8x8_cad_SendCmd(u8x8_t *u8x8, uint8_t cmd)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_CMD, cmd, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_SendArg(u8x8_t *u8x8, uint8_t arg)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_ARG, arg, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_SendMultipleArg(u8x8_t *u8x8, uint8_t cnt, uint8_t arg)
|
||||
{
|
||||
while( cnt > 0 )
|
||||
{
|
||||
u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_ARG, arg, NULL);
|
||||
cnt--;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_SendData(u8x8_t *u8x8, uint8_t cnt, uint8_t *data)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, cnt, data);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_StartTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
uint8_t u8x8_cad_EndTransfer(u8x8_t *u8x8)
|
||||
{
|
||||
return u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
|
||||
}
|
||||
|
||||
void u8x8_cad_vsendf(u8x8_t * u8x8, const char *fmt, va_list va)
|
||||
{
|
||||
uint8_t d;
|
||||
u8x8_cad_StartTransfer(u8x8);
|
||||
while( *fmt != '\0' )
|
||||
{
|
||||
d = (uint8_t)va_arg(va, int);
|
||||
switch(*fmt)
|
||||
{
|
||||
case 'a': u8x8_cad_SendArg(u8x8, d); break;
|
||||
case 'c': u8x8_cad_SendCmd(u8x8, d); break;
|
||||
case 'd': u8x8_cad_SendData(u8x8, 1, &d); break;
|
||||
}
|
||||
fmt++;
|
||||
}
|
||||
u8x8_cad_EndTransfer(u8x8);
|
||||
}
|
||||
|
||||
void u8x8_SendF(u8x8_t * u8x8, const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
u8x8_cad_vsendf(u8x8, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
/*
|
||||
21 c send command c
|
||||
22 a send arg a
|
||||
23 d send data d
|
||||
24 CS on
|
||||
25 CS off
|
||||
254 milli delay by milliseconds
|
||||
255 end of sequence
|
||||
*/
|
||||
|
||||
void u8x8_cad_SendSequence(u8x8_t *u8x8, uint8_t const *data)
|
||||
{
|
||||
uint8_t cmd;
|
||||
uint8_t v;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
cmd = *data;
|
||||
data++;
|
||||
switch( cmd )
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
v = *data;
|
||||
u8x8->cad_cb(u8x8, cmd, v, NULL);
|
||||
data++;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
v = *data;
|
||||
u8x8_cad_SendData(u8x8, 1, &v);
|
||||
data++;
|
||||
break;
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
u8x8->cad_cb(u8x8, cmd, 0, NULL);
|
||||
break;
|
||||
case 0x0fe:
|
||||
v = *data;
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, v);
|
||||
data++;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t u8x8_cad_empty(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 1 for commands and args and
|
||||
dc = 0 for data
|
||||
*/
|
||||
uint8_t u8x8_cad_110(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 1 for commands and args and
|
||||
dc = 0 for data
|
||||
*/
|
||||
uint8_t u8x8_gu800_cad_110(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *data;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
data = (uint8_t *)arg_ptr;
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, *data);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
break;
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 1 for commands and args and
|
||||
dc = 0 for data
|
||||
t6963
|
||||
*/
|
||||
uint8_t u8x8_cad_100(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 0 for commands and args and
|
||||
dc = 1 for data
|
||||
*/
|
||||
uint8_t u8x8_cad_001(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
convert to bytes by using
|
||||
dc = 0 for commands
|
||||
dc = 1 for args and data
|
||||
*/
|
||||
uint8_t u8x8_cad_011(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
u8x8_byte_SetDC(u8x8, 1);
|
||||
//u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr);
|
||||
//break;
|
||||
/* fall through */
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cad procedure for the ST7920 in SPI mode */
|
||||
/* u8x8_byte_SetDC is not used */
|
||||
uint8_t u8x8_cad_st7920_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *data;
|
||||
uint8_t b;
|
||||
uint8_t i;
|
||||
static uint8_t buf[16];
|
||||
uint8_t *ptr;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_SendByte(u8x8, 0x0f8);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int & 0x0f0);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
u8x8_byte_SendByte(u8x8, arg_int << 4);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, 0x0f8);
|
||||
u8x8_byte_SendByte(u8x8, arg_int & 0x0f0);
|
||||
u8x8_byte_SendByte(u8x8, arg_int << 4);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
|
||||
u8x8_byte_SendByte(u8x8, 0x0fa);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
|
||||
/* this loop should be optimized: multiple bytes should be sent */
|
||||
/* u8x8_byte_SendBytes(u8x8, arg_int, arg_ptr); */
|
||||
data = (uint8_t *)arg_ptr;
|
||||
|
||||
/* the following loop increases speed by 20% */
|
||||
while( arg_int >= 8 )
|
||||
{
|
||||
i = 8;
|
||||
ptr = buf;
|
||||
do
|
||||
{
|
||||
b = *data++;
|
||||
*ptr++= b & 0x0f0;
|
||||
b <<= 4;
|
||||
*ptr++= b;
|
||||
i--;
|
||||
} while( i > 0 );
|
||||
arg_int -= 8;
|
||||
u8x8_byte_SendBytes(u8x8, 16, buf);
|
||||
}
|
||||
|
||||
|
||||
while( arg_int > 0 )
|
||||
{
|
||||
b = *data;
|
||||
u8x8_byte_SendByte(u8x8, b & 0x0f0);
|
||||
u8x8_byte_SendByte(u8x8, b << 4);
|
||||
data++;
|
||||
arg_int--;
|
||||
}
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_NANO, 1);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* cad procedure for the SSD13xx family in I2C mode */
|
||||
/* this procedure is also used by the ST7588 */
|
||||
/* u8x8_byte_SetDC is not used */
|
||||
/* U8X8_MSG_BYTE_START_TRANSFER starts i2c transfer, U8X8_MSG_BYTE_END_TRANSFER stops transfer */
|
||||
/* After transfer start, a full byte indicates command or data mode */
|
||||
|
||||
static void u8x8_i2c_data_transfer(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr) U8X8_NOINLINE;
|
||||
static void u8x8_i2c_data_transfer(u8x8_t *u8x8, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x040);
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, arg_ptr);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
}
|
||||
|
||||
/* classic version: will put a start/stop condition around each command and arg */
|
||||
uint8_t u8x8_cad_ssd13xx_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
/* 7 Nov 2016: Can this be improved? */
|
||||
//u8x8_byte_SetDC(u8x8, 0);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
//u8x8_byte_SendByte(u8x8, u8x8_GetI2CAddress(u8x8));
|
||||
u8x8_byte_SendByte(u8x8, 0x000);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
//u8x8_byte_SetDC(u8x8, 1);
|
||||
|
||||
/* the FeatherWing OLED with the 32u4 transfer of long byte */
|
||||
/* streams was not possible. This is broken down to */
|
||||
/* smaller streams, 32 seems to be the limit... */
|
||||
/* I guess this is related to the size of the Wire buffers in Arduino */
|
||||
/* Unfortunately, this can not be handled in the byte level drivers, */
|
||||
/* so this is done here. Even further, only 24 bytes will be sent, */
|
||||
/* because there will be another byte (DC) required during the transfer */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8_i2c_data_transfer(u8x8, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
}
|
||||
u8x8_i2c_data_transfer(u8x8, arg_int, p);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
/* cad transfer commands are ignored */
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* fast version with reduced data start/stops, issue 735 */
|
||||
uint8_t u8x8_cad_ssd13xx_fast_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
/* improved version, takeover from ld7032 */
|
||||
/* assumes, that the args of a command is not longer than 31 bytes */
|
||||
/* speed improvement is about 4% compared to the classic version */
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x000); /* cmd byte for ssd13xx controller */
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
/* lightning version: can replace the improved version from above */
|
||||
/* the drawback of the lightning version is this: The complete init sequence */
|
||||
/* must fit into the 32 byte Arduino Wire buffer, which might not always be the case */
|
||||
/* speed improvement is about 6% compared to the classic version */
|
||||
// if ( in_transfer == 0 )
|
||||
// {
|
||||
// u8x8_byte_StartTransfer(u8x8);
|
||||
// u8x8_byte_SendByte(u8x8, 0x000); /* cmd byte for ssd13xx controller */
|
||||
// in_transfer = 1;
|
||||
// }
|
||||
//u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
|
||||
|
||||
/* the FeatherWing OLED with the 32u4 transfer of long byte */
|
||||
/* streams was not possible. This is broken down to */
|
||||
/* smaller streams, 32 seems to be the limit... */
|
||||
/* I guess this is related to the size of the Wire buffers in Arduino */
|
||||
/* Unfortunately, this can not be handled in the byte level drivers, */
|
||||
/* so this is done here. Even further, only 24 bytes will be sent, */
|
||||
/* because there will be another byte (DC) required during the transfer */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8_i2c_data_transfer(u8x8, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
}
|
||||
u8x8_i2c_data_transfer(u8x8, arg_int, p);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* the st75256 i2c driver is a copy of the ssd13xx driver, but with arg=1 */
|
||||
/* modified from cad001 (ssd13xx) to cad011 */
|
||||
uint8_t u8x8_cad_st75256_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x000);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x040);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
/* see ssd13xx driver */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8_i2c_data_transfer(u8x8, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
}
|
||||
u8x8_i2c_data_transfer(u8x8, arg_int, p);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078; /* ST75256, often this is 0x07e */
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
/* cad transfer commands are ignored */
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cad i2c procedure for the ld7032 controller */
|
||||
/* Issue https://github.com/olikraus/u8g2/issues/865 mentiones, that I2C does not work */
|
||||
/* Workaround is to remove the while loop (or increase the value in the condition) */
|
||||
uint8_t u8x8_cad_ld7032_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
//u8x8_byte_SetDC(u8x8, 1);
|
||||
|
||||
/* the FeatherWing OLED with the 32u4 transfer of long byte */
|
||||
/* streams was not possible. This is broken down to */
|
||||
/* smaller streams, 32 seems to be the limit... */
|
||||
/* I guess this is related to the size of the Wire buffers in Arduino */
|
||||
/* Unfortunately, this can not be handled in the byte level drivers, */
|
||||
/* so this is done here. Even further, only 24 bytes will be sent, */
|
||||
/* because there will be another byte (DC) required during the transfer */
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
u8x8_byte_SendByte(u8x8, 0x08); /* data write for LD7032 */
|
||||
}
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x060;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* cad procedure for the UC16xx family in I2C mode */
|
||||
/* u8x8_byte_SetDC is not used */
|
||||
/* DC bit is encoded into the adr byte, structure is CAD001 */
|
||||
uint8_t u8x8_cad_uc16xx_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
static uint8_t is_data = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data != 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
// is_data = 0; // 20 Jun 2021: I assume that this is missing here
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data == 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
in_transfer = 1;
|
||||
// is_data = 1; // 20 Jun 2021: I assume that this is missing here
|
||||
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
|
||||
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x070;
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
/* actual start is delayed, because we do not whether this is data or cmd transfer */
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* cad procedure for the UC1638 in I2C mode */
|
||||
/* same as u8x8_cad_uc16xx_i2c but CAD structure is CAD011 */
|
||||
uint8_t u8x8_cad_uc1638_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
static uint8_t in_transfer = 0;
|
||||
static uint8_t is_data = 0;
|
||||
uint8_t *p;
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_CAD_SEND_CMD:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data != 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, u8x8_GetI2CAddress(u8x8)&0x0fc );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
is_data = 0;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_ARG:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data == 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8_byte_SendByte(u8x8, arg_int);
|
||||
in_transfer = 1;
|
||||
is_data = 1;
|
||||
break;
|
||||
case U8X8_MSG_CAD_SEND_DATA:
|
||||
if ( in_transfer != 0 )
|
||||
{
|
||||
if ( is_data == 0 )
|
||||
{
|
||||
/* transfer mode is active, but data transfer */
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* clear the lowest two bits of the adr */
|
||||
u8x8_SetI2CAddress( u8x8, (u8x8_GetI2CAddress(u8x8)&0x0fc)|2 );
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
in_transfer = 1;
|
||||
is_data = 1;
|
||||
|
||||
p = arg_ptr;
|
||||
while( arg_int > 24 )
|
||||
{
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, 24, p);
|
||||
arg_int-=24;
|
||||
p+=24;
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
u8x8_byte_StartTransfer(u8x8);
|
||||
}
|
||||
u8x8->byte_cb(u8x8, U8X8_MSG_CAD_SEND_DATA, arg_int, p);
|
||||
|
||||
break;
|
||||
case U8X8_MSG_CAD_INIT:
|
||||
/* apply default i2c adr if required so that the start transfer msg can use this */
|
||||
if ( u8x8->i2c_address == 255 )
|
||||
u8x8->i2c_address = 0x078; /* see also https://github.com/olikraus/u8g2/issues/371 for a discussion on this value */
|
||||
return u8x8->byte_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
case U8X8_MSG_CAD_START_TRANSFER:
|
||||
in_transfer = 0;
|
||||
/* actual start is delayed, because we do not whether this is data or cmd transfer */
|
||||
break;
|
||||
case U8X8_MSG_CAD_END_TRANSFER:
|
||||
if ( in_transfer != 0 )
|
||||
u8x8_byte_EndTransfer(u8x8);
|
||||
in_transfer = 0;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
255
Middlewares/u8g2Lib/src/u8x8_capture.c
Normal file
255
Middlewares/u8g2Lib/src/u8x8_capture.c
Normal file
@ -0,0 +1,255 @@
|
||||
/*
|
||||
|
||||
u8x8_capture.c
|
||||
|
||||
Screen capture funcion
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
/*========================================================*/
|
||||
|
||||
|
||||
/* vertical top lsb memory architecture */
|
||||
uint8_t u8x8_capture_get_pixel_1(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width)
|
||||
{
|
||||
//uint8_t *dest_ptr = capture->buffer;
|
||||
//if ( dest_ptr == NULL )
|
||||
//return 0;
|
||||
//dest_ptr += (y/8)*capture->tile_width*8;
|
||||
dest_ptr += (y/8)*tile_width*8;
|
||||
y &= 7;
|
||||
dest_ptr += x;
|
||||
if ( (*dest_ptr & (1<<y)) == 0 )
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* horizontal right lsb memory architecture */
|
||||
/* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
|
||||
uint8_t u8x8_capture_get_pixel_2(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width)
|
||||
{
|
||||
//uint8_t *dest_ptr = capture->buffer;
|
||||
//if ( dest_ptr == NULL )
|
||||
// return 0;
|
||||
//dest_ptr += y*capture->tile_width;
|
||||
y *= tile_width;
|
||||
dest_ptr += y;
|
||||
dest_ptr += x>>3;
|
||||
if ( (*dest_ptr & (128>>(x&7))) == 0 )
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void u8x8_capture_write_pbm_pre(uint8_t tile_width, uint8_t tile_height, void (*out)(const char *s))
|
||||
{
|
||||
out("P1\n");
|
||||
out(u8x8_utoa((uint16_t)tile_width*8));
|
||||
out("\n");
|
||||
out(u8x8_utoa((uint16_t)tile_height*8));
|
||||
out("\n");
|
||||
}
|
||||
|
||||
|
||||
void u8x8_capture_write_pbm_buffer(uint8_t *buffer, uint8_t tile_width, uint8_t tile_height, uint8_t (*get_pixel)(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width), void (*out)(const char *s))
|
||||
{
|
||||
uint16_t x, y;
|
||||
uint16_t w, h;
|
||||
|
||||
w = tile_width;
|
||||
w *= 8;
|
||||
h = tile_height;
|
||||
h *= 8;
|
||||
|
||||
for( y = 0; y < h; y++)
|
||||
{
|
||||
for( x = 0; x < w; x++)
|
||||
{
|
||||
if ( get_pixel(x, y, buffer, tile_width) )
|
||||
out("1");
|
||||
else
|
||||
out("0");
|
||||
}
|
||||
out("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void u8x8_capture_write_xbm_pre(uint8_t tile_width, uint8_t tile_height, void (*out)(const char *s))
|
||||
{
|
||||
out("#define xbm_width ");
|
||||
out(u8x8_utoa((uint16_t)tile_width*8));
|
||||
out("\n");
|
||||
out("#define xbm_height ");
|
||||
out(u8x8_utoa((uint16_t)tile_height*8));
|
||||
out("\n");
|
||||
out("static unsigned char xbm_bits[] = {\n");
|
||||
}
|
||||
|
||||
void u8x8_capture_write_xbm_buffer(uint8_t *buffer, uint8_t tile_width, uint8_t tile_height, uint8_t (*get_pixel)(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width), void (*out)(const char *s))
|
||||
{
|
||||
uint16_t x, y;
|
||||
uint16_t w, h;
|
||||
uint8_t v, b;
|
||||
char s[2];
|
||||
s[1] = '\0';
|
||||
|
||||
w = tile_width;
|
||||
w *= 8;
|
||||
h = tile_height;
|
||||
h *= 8;
|
||||
|
||||
y = 0;
|
||||
for(;;)
|
||||
{
|
||||
x = 0;
|
||||
for(;;)
|
||||
{
|
||||
v = 0;
|
||||
for( b = 0; b < 8; b++ )
|
||||
{
|
||||
v <<= 1;
|
||||
if ( get_pixel(x+7-b, y, buffer, tile_width) )
|
||||
v |= 1;
|
||||
}
|
||||
out("0x");
|
||||
s[0] = (v>>4);
|
||||
if ( s[0] <= 9 )
|
||||
s[0] += '0';
|
||||
else
|
||||
s[0] += 'a'-10;
|
||||
out(s);
|
||||
s[0] = (v&15);
|
||||
if ( s[0] <= 9 )
|
||||
s[0] += '0';
|
||||
else
|
||||
s[0] += 'a'-10;
|
||||
out(s);
|
||||
x += 8;
|
||||
if ( x >= w )
|
||||
break;
|
||||
out(",");
|
||||
}
|
||||
y++;
|
||||
if ( y >= h )
|
||||
break;
|
||||
out(",");
|
||||
out("\n");
|
||||
}
|
||||
out("};\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*========================================================*/
|
||||
|
||||
#ifdef NOT_YET_IMPLEMENTED_U8X8_SCREEN_CAPTURE
|
||||
|
||||
struct _u8x8_capture_struct
|
||||
{
|
||||
u8x8_msg_cb old_cb;
|
||||
uint8_t *buffer; /* tile_width*tile_height*8 bytes */
|
||||
uint8_t tile_width;
|
||||
uint8_t tile_height;
|
||||
};
|
||||
typedef struct _u8x8_capture_struct u8x8_capture_t;
|
||||
|
||||
|
||||
u8x8_capture_t u8x8_capture;
|
||||
|
||||
|
||||
static void u8x8_capture_memory_copy(uint8_t *dest, uint8_t *src, uint16_t cnt)
|
||||
{
|
||||
while( cnt > 0 )
|
||||
{
|
||||
*dest++ = *src++;
|
||||
cnt--;
|
||||
}
|
||||
}
|
||||
|
||||
static void u8x8_capture_DrawTiles(u8x8_capture_t *capture, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t *tile_ptr)
|
||||
{
|
||||
uint8_t *dest_ptr = capture->buffer;
|
||||
//printf("tile pos: %d %d, cnt=%d\n", tx, ty, tile_cnt);
|
||||
if ( dest_ptr == NULL )
|
||||
return;
|
||||
dest_ptr += (uint16_t)ty*capture->tile_width*8;
|
||||
dest_ptr += (uint16_t)tx*8;
|
||||
u8x8_capture_memory_copy(dest_ptr, tile_ptr, tile_cnt*8);
|
||||
}
|
||||
|
||||
uint8_t u8x8_d_capture(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
if ( msg == U8X8_MSG_DISPLAY_DRAW_TILE )
|
||||
{
|
||||
uint8_t x, y, c;
|
||||
uint8_t *ptr;
|
||||
x = ((u8x8_tile_t *)arg_ptr)->x_pos;
|
||||
y = ((u8x8_tile_t *)arg_ptr)->y_pos;
|
||||
c = ((u8x8_tile_t *)arg_ptr)->cnt;
|
||||
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
|
||||
do
|
||||
{
|
||||
u8x8_capture_DrawTiles(&u8x8_capture, x, y, c, ptr);
|
||||
x += c;
|
||||
arg_int--;
|
||||
} while( arg_int > 0 );
|
||||
}
|
||||
return u8x8_capture.old_cb(u8x8, msg, arg_int, arg_ptr);
|
||||
}
|
||||
|
||||
uint8_t u8x8_GetCaptureMemoryPixel(u8x8_t *u8x8, uint16_t x, uint16_t y)
|
||||
{
|
||||
return u8x8_capture_GetPixel(&u8x8_capture, x, y);
|
||||
}
|
||||
|
||||
/* memory: tile_width*tile_height*8 bytes */
|
||||
void u8x8_ConnectCapture(u8x8_t *u8x8, uint8_t tile_width, uint8_t tile_height, uint8_t *memory)
|
||||
{
|
||||
if ( u8x8->display_cb == u8x8_d_capture )
|
||||
return; /* do nothing, capture already installed */
|
||||
|
||||
u8x8_capture.buffer = memory; /* tile_width*tile_height*8 bytes */
|
||||
u8x8_capture.tile_width = tile_width;
|
||||
u8x8_capture.tile_height = tile_height;
|
||||
u8x8_capture.old_cb = u8x8->display_cb;
|
||||
u8x8->display_cb = u8x8_d_capture;
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
544
Middlewares/u8g2Lib/src/u8x8_d_ssd1306_128x64_noname.c
Normal file
544
Middlewares/u8g2Lib/src/u8x8_d_ssd1306_128x64_noname.c
Normal file
@ -0,0 +1,544 @@
|
||||
/*
|
||||
|
||||
u8x8_d_ssd1306_128x64_noname.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
|
||||
|
||||
/* more or less generic setup of all these small OLEDs */
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_noname_init_seq[] = {
|
||||
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
|
||||
|
||||
U8X8_C(0x0ae), /* display off */
|
||||
U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
|
||||
U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */
|
||||
U8X8_CA(0x0d3, 0x000), /* display offset */
|
||||
U8X8_C(0x040), /* set display start line to 0 */
|
||||
U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, SSD1306 only, should be removed for SH1106 */
|
||||
U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
|
||||
|
||||
U8X8_C(0x0a1), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
|
||||
// Flipmode
|
||||
// U8X8_C(0x0a0), /* segment remap a0/a1*/
|
||||
// U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
|
||||
U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
|
||||
|
||||
U8X8_CA(0x081, 0x0cf), /* [2] set contrast control */
|
||||
U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/
|
||||
U8X8_CA(0x0db, 0x040), /* vcomh deselect level */
|
||||
// if vcomh is 0, then this will give the biggest range for contrast control issue #98
|
||||
// restored the old values for the noname constructor, because vcomh=0 will not work for all OLEDs, #116
|
||||
|
||||
U8X8_C(0x02e), /* Deactivate scroll */
|
||||
U8X8_C(0x0a4), /* output ram to display */
|
||||
U8X8_C(0x0a6), /* none inverted normal display mode */
|
||||
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
/* this setup maximizes the brightness range, that can be set with setContrast() */
|
||||
/* Drawback: VCOMH deselect level is set to 0, which das not work so good with all OLEDs, issue #116 */
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_vcomh0_init_seq[] = {
|
||||
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
|
||||
|
||||
U8X8_C(0x0ae), /* display off */
|
||||
U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
|
||||
U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */
|
||||
U8X8_CA(0x0d3, 0x000), /* display offset */
|
||||
U8X8_C(0x040), /* set display start line to 0 */
|
||||
U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable */
|
||||
U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
|
||||
|
||||
U8X8_C(0x0a1), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
|
||||
// Flipmode
|
||||
// U8X8_C(0x0a0), /* segment remap a0/a1*/
|
||||
// U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
|
||||
U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
|
||||
U8X8_CA(0x081, 0x0ef), /* [2] set contrast control, */
|
||||
U8X8_CA(0x0d9, 0x0a1), /* [2] pre-charge period 0x022/f1*/
|
||||
U8X8_CA(0x0db, 0x000), /* vcomh deselect level 0x000 .. 0x070, low nibble always 0 */
|
||||
// if vcomh is 0, then this will give the biggest range for contrast control issue #98
|
||||
|
||||
U8X8_C(0x02e), /* Deactivate scroll */
|
||||
U8X8_C(0x0a4), /* output ram to display */
|
||||
U8X8_C(0x0a6), /* none inverted normal display mode */
|
||||
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
/* same as u8x8_d_ssd1306_128x64_noname_init_seq, but 0x0da bit 4 is set to 0 */
|
||||
/* this will disable the alternative COM configuration */
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_alt0_init_seq[] = {
|
||||
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
|
||||
|
||||
U8X8_C(0x0ae), /* display off */
|
||||
U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
|
||||
U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */
|
||||
U8X8_CA(0x0d3, 0x000), /* display offset */
|
||||
U8X8_C(0x040), /* set display start line to 0 */
|
||||
U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, SSD1306 only, should be removed for SH1106 */
|
||||
U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
|
||||
|
||||
U8X8_C(0x0a1), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
|
||||
// Flipmode
|
||||
// U8X8_C(0x0a0), /* segment remap a0/a1*/
|
||||
// U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
|
||||
U8X8_CA(0x0da, 0x002), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
|
||||
|
||||
U8X8_CA(0x081, 0x0cf), /* [2] set contrast control */
|
||||
U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/
|
||||
U8X8_CA(0x0db, 0x040), /* vcomh deselect level */
|
||||
// if vcomh is 0, then this will give the biggest range for contrast control issue #98
|
||||
// restored the old values for the noname constructor, because vcomh=0 will not work for all OLEDs, #116
|
||||
|
||||
U8X8_C(0x02e), /* Deactivate scroll */
|
||||
U8X8_C(0x0a4), /* output ram to display */
|
||||
U8X8_C(0x0a6), /* none inverted normal display mode */
|
||||
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/* issue 316: a special sh1106 setup, https://www.mikrocontroller.net/topic/431371?goto=5087807#5087807 */
|
||||
static const uint8_t u8x8_d_sh1106_128x64_winstar_init_seq[] = {
|
||||
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
|
||||
U8X8_C(0xae), // Display OFF/ON: off (POR = 0xae)
|
||||
U8X8_C(0xa4), // Set Entire Display OFF/ON: off (POR = 0xa4)
|
||||
U8X8_CA(0xd5, 0x50), // Divide Ratio/Oscillator FrequencyData Set: divide ratio = 1 (POR = 1), Oscillator Frequency = +/- 0% (POR = +/- 0%)
|
||||
U8X8_CA(0xa8, 0x3f), // Multiplex Ratio Data Set: 64 (POR = 0x3f, 64)
|
||||
U8X8_CA(0xd3, 0x00), // Display OffsetData Set: 0 (POR = 0x00)
|
||||
U8X8_C(0x40), // Set Display Start Line: 0
|
||||
U8X8_CA(0xad, 0x8b), // DC-DC ON/OFF Mode Set: Built-in DC-DC is used, Normal Display (POR = 0x8b)
|
||||
U8X8_CA(0xd9, 0x22), // Dis-charge/Pre-charge PeriodData Set: pre-charge 2 DCLKs, dis-charge 2 DCLKs (POR = 0x22, pre-charge 2 DCLKs, dis-charge 2 DCLKs)
|
||||
U8X8_CA(0xdb, 0x35), // VCOM Deselect LevelData Set: 0,770V (POR = 0x35, 0,770 V)
|
||||
U8X8_C(0x32), // Set Pump voltage value: 8,0 V (POR = 0x32, 8,0 V)
|
||||
U8X8_CA(0x81, 0xff), // Contrast Data Register Set: 255 (large) (POR = 0x80)
|
||||
U8X8_C(0x0a6), // Set Normal/Reverse Display: normal (POR = 0xa6)
|
||||
U8X8_CA(0x0da, 0x012), // com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5)
|
||||
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8x8_d_ssd1312_128x64_noname_init_seq[] = {
|
||||
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
|
||||
|
||||
U8X8_C(0x0ae), /* display off */
|
||||
U8X8_CA(0x0d5, 0x080), /* clock divide ratio (0x00=1) and oscillator frequency (0x8) */
|
||||
U8X8_CA(0x0a8, 0x03f), /* multiplex ratio */
|
||||
U8X8_CA(0x0d3, 0x000), /* display offset */
|
||||
U8X8_C(0x040), /* set display start line to 0 */
|
||||
U8X8_CA(0x08d, 0x014), /* [2] charge pump setting (p62): 0x014 enable, 0x010 disable, SSD1306 only, should be removed for SH1106 */
|
||||
U8X8_CA(0x020, 0x000), /* horizontal addressing mode */
|
||||
|
||||
U8X8_C(0x0a1), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
|
||||
U8X8_CA(0x0da, 0x012), /* com pin HW config, sequential com pin config (bit 4), disable left/right remap (bit 5) */
|
||||
|
||||
U8X8_CA(0x081, 0x0cf), /* [2] set contrast control */
|
||||
U8X8_CA(0x0d9, 0x0f1), /* [2] pre-charge period 0x022/f1*/
|
||||
U8X8_CA(0x0db, 0x040), /* vcomh deselect level */
|
||||
// if vcomh is 0, then this will give the biggest range for contrast control issue #98
|
||||
// restored the old values for the noname constructor, because vcomh=0 will not work for all OLEDs, #116
|
||||
|
||||
U8X8_C(0x02e), /* Deactivate scroll */
|
||||
U8X8_C(0x0a4), /* output ram to display */
|
||||
U8X8_C(0x0a6), /* none inverted normal display mode */
|
||||
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_noname_powersave0_seq[] = {
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
U8X8_C(0x0af), /* display on */
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_noname_powersave1_seq[] = {
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
U8X8_C(0x0ae), /* display off */
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_noname_flip0_seq[] = {
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
U8X8_C(0x0a1), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8x8_d_ssd1306_128x64_noname_flip1_seq[] = {
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
U8X8_C(0x0a0), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8x8_d_ssd1312_128x64_noname_flip0_seq[] = {
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
U8X8_C(0x0a1), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c0), /* c0: scan dir normal, c8: reverse */
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static const uint8_t u8x8_d_ssd1312_128x64_noname_flip1_seq[] = {
|
||||
U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
|
||||
U8X8_C(0x0a0), /* segment remap a0/a1*/
|
||||
U8X8_C(0x0c8), /* c0: scan dir normal, c8: reverse */
|
||||
U8X8_END_TRANSFER(), /* disable chip */
|
||||
U8X8_END() /* end of sequence */
|
||||
};
|
||||
|
||||
static uint8_t u8x8_d_ssd1306_sh1106_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
uint8_t x, c;
|
||||
uint8_t *ptr;
|
||||
switch(msg)
|
||||
{
|
||||
/* handled by the calling function
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_128x64_noname_display_info);
|
||||
break;
|
||||
*/
|
||||
/* handled by the calling function
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_init_seq);
|
||||
break;
|
||||
*/
|
||||
case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
|
||||
if ( arg_int == 0 )
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_powersave0_seq);
|
||||
else
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_powersave1_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
|
||||
if ( arg_int == 0 )
|
||||
{
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_flip0_seq);
|
||||
u8x8->x_offset = u8x8->display_info->default_x_offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_flip1_seq);
|
||||
u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
|
||||
}
|
||||
break;
|
||||
#ifdef U8X8_WITH_SET_CONTRAST
|
||||
case U8X8_MSG_DISPLAY_SET_CONTRAST:
|
||||
u8x8_cad_StartTransfer(u8x8);
|
||||
u8x8_cad_SendCmd(u8x8, 0x081 );
|
||||
u8x8_cad_SendArg(u8x8, arg_int ); /* ssd1306 has range from 0 to 255 */
|
||||
u8x8_cad_EndTransfer(u8x8);
|
||||
break;
|
||||
#endif
|
||||
case U8X8_MSG_DISPLAY_DRAW_TILE:
|
||||
u8x8_cad_StartTransfer(u8x8);
|
||||
x = ((u8x8_tile_t *)arg_ptr)->x_pos;
|
||||
x *= 8;
|
||||
x += u8x8->x_offset;
|
||||
|
||||
u8x8_cad_SendCmd(u8x8, 0x040 ); /* set line offset to 0 */
|
||||
|
||||
u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4) );
|
||||
u8x8_cad_SendArg(u8x8, 0x000 | ((x&15))); /* probably wrong, should be SendCmd */
|
||||
u8x8_cad_SendArg(u8x8, 0x0b0 | (((u8x8_tile_t *)arg_ptr)->y_pos)); /* probably wrong, should be SendCmd */
|
||||
|
||||
|
||||
do
|
||||
{
|
||||
c = ((u8x8_tile_t *)arg_ptr)->cnt;
|
||||
ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
|
||||
u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
|
||||
/*
|
||||
do
|
||||
{
|
||||
u8x8_cad_SendData(u8x8, 8, ptr);
|
||||
ptr += 8;
|
||||
c--;
|
||||
} while( c > 0 );
|
||||
*/
|
||||
arg_int--;
|
||||
} while( arg_int > 0 );
|
||||
|
||||
u8x8_cad_EndTransfer(u8x8);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const u8x8_display_info_t u8x8_ssd1306_128x64_noname_display_info =
|
||||
{
|
||||
/* chip_enable_level = */ 0,
|
||||
/* chip_disable_level = */ 1,
|
||||
|
||||
/* post_chip_enable_wait_ns = */ 20,
|
||||
/* pre_chip_disable_wait_ns = */ 10,
|
||||
/* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
|
||||
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
|
||||
/* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
|
||||
/* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
|
||||
/* sck_clock_hz = */ 8000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
|
||||
/* spi_mode = */ 0, /* active high, rising edge */
|
||||
/* i2c_bus_clock_100kHz = */ 4,
|
||||
/* data_setup_time_ns = */ 40,
|
||||
/* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
|
||||
/* tile_width = */ 16,
|
||||
/* tile_height = */ 8,
|
||||
/* default_x_offset = */ 0,
|
||||
/* flipmode_x_offset = */ 0,
|
||||
/* pixel_width = */ 128,
|
||||
/* pixel_height = */ 64
|
||||
};
|
||||
|
||||
uint8_t u8x8_d_ssd1306_128x64_noname(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_init_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_d_ssd1312_128x64_noname(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
|
||||
if ( arg_int == 0 )
|
||||
{
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x64_noname_flip0_seq);
|
||||
u8x8->x_offset = u8x8->display_info->default_x_offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x64_noname_flip1_seq);
|
||||
u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
|
||||
}
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1312_128x64_noname_init_seq); /* update 27 mar 2022 */
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t u8x8_d_ssd1306_128x64_vcomh0(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_vcomh0_init_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t u8x8_d_ssd1306_128x64_alt0(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_alt0_init_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ssd1306_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const u8x8_display_info_t u8x8_sh1106_128x64_noname_display_info =
|
||||
{
|
||||
/* chip_enable_level = */ 0,
|
||||
/* chip_disable_level = */ 1,
|
||||
|
||||
/* post_chip_enable_wait_ns = */ 20,
|
||||
/* pre_chip_disable_wait_ns = */ 10,
|
||||
/* reset_pulse_width_ms = */ 100, /* SSD1306: 3 us */
|
||||
/* post_reset_wait_ms = */ 100, /* far east OLEDs need much longer setup time */
|
||||
/* sda_setup_time_ns = */ 50, /* SSD1306: 15ns, but cycle time is 100ns, so use 100/2 */
|
||||
/* sck_pulse_width_ns = */ 50, /* SSD1306: 20ns, but cycle time is 100ns, so use 100/2, AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
|
||||
/* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns, increased to 8MHz (issue 215) */
|
||||
/* spi_mode = */ 0, /* issue 1901: changed mode from 3 to 0 */
|
||||
/* i2c_bus_clock_100kHz = */ 4,
|
||||
/* data_setup_time_ns = */ 40,
|
||||
/* write_pulse_width_ns = */ 150, /* SSD1306: cycle time is 300ns, so use 300/2 = 150 */
|
||||
/* tile_width = */ 16,
|
||||
/* tile_height = */ 8,
|
||||
/* default_x_offset = */ 2,
|
||||
/* flipmode_x_offset = */ 2,
|
||||
/* pixel_width = */ 128,
|
||||
/* pixel_height = */ 64
|
||||
};
|
||||
|
||||
uint8_t u8x8_d_sh1106_128x64_noname(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
/* maybe use a better init sequence */
|
||||
/* https://www.mikrocontroller.net/topic/431371 */
|
||||
/* the new sequence is added in the winstar constructor (see below), this is kept untouched */
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_noname_init_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sh1106_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
uint8_t u8x8_d_sh1106_128x64_vcomh0(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_ssd1306_128x64_vcomh0_init_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sh1106_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
uint8_t u8x8_d_sh1106_128x64_winstar(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
|
||||
{
|
||||
if ( u8x8_d_ssd1306_sh1106_generic(u8x8, msg, arg_int, arg_ptr) != 0 )
|
||||
return 1;
|
||||
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
u8x8_cad_SendSequence(u8x8, u8x8_d_sh1106_128x64_winstar_init_seq);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sh1106_128x64_noname_display_info);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
205
Middlewares/u8g2Lib/src/u8x8_debounce.c
Normal file
205
Middlewares/u8g2Lib/src/u8x8_debounce.c
Normal file
@ -0,0 +1,205 @@
|
||||
/*
|
||||
|
||||
u8x8_debounce.c
|
||||
|
||||
Key/button simple debounce algorithm (Addon for u8x8)
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
static uint8_t u8x8_read_pin_state(u8x8_t *u8x8)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t pin_state;
|
||||
|
||||
pin_state = 255; /* be compatible with the setup of the default pin setup, which is 255 */
|
||||
for( i = 0; i < U8X8_PIN_INPUT_CNT; i++ )
|
||||
{
|
||||
pin_state <<= 1;
|
||||
|
||||
/* the callback function should put the return value into this variable */
|
||||
u8x8->gpio_result = 1;
|
||||
u8x8_gpio_call(u8x8, U8X8_MSG_GPIO(i+U8X8_PIN_OUTPUT_CNT), 0);
|
||||
pin_state |= u8x8->gpio_result & 1;
|
||||
}
|
||||
|
||||
return pin_state;
|
||||
}
|
||||
|
||||
/*
|
||||
return 0 to U8X8_PIN_INPUT_CNT-1 if there is a difference
|
||||
return U8X8_PIN_INPUT_CNT if there is no difference
|
||||
*/
|
||||
static uint8_t u8x8_find_first_diff(uint8_t a, uint8_t b)
|
||||
{
|
||||
uint8_t mask;
|
||||
uint8_t i;
|
||||
mask = 1;
|
||||
i = U8X8_PIN_INPUT_CNT;
|
||||
do
|
||||
{
|
||||
i--;
|
||||
if ( (a & mask) != (b & mask) )
|
||||
return i;
|
||||
mask <<= 1;
|
||||
} while( i > 0 );
|
||||
return U8X8_PIN_INPUT_CNT;
|
||||
}
|
||||
|
||||
/*
|
||||
State A:
|
||||
u8x8->debounce_last_pin_state == current_state
|
||||
--> State A
|
||||
u8x8->debounce_last_pin_state != current_state
|
||||
--> u8x8->debounce_last_pin_state = current_state
|
||||
--> State B + cnt
|
||||
|
||||
State B + cnt
|
||||
--> state--
|
||||
|
||||
State B
|
||||
u8x8->debounce_last_pin_state == current_state
|
||||
--> keypress detected
|
||||
--> State C
|
||||
u8x8->debounce_last_pin_state != current_state
|
||||
--> State A
|
||||
|
||||
State C
|
||||
u8x8->debounce_last_pin_state == current_state
|
||||
--> State C
|
||||
u8x8->debounce_last_pin_state != current_state
|
||||
--> State A
|
||||
|
||||
*/
|
||||
|
||||
#ifdef __unix__xxxxxx_THIS_IS_DISABLED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
|
||||
{
|
||||
int c;
|
||||
c = getc(stdin);
|
||||
switch(c)
|
||||
{
|
||||
case 'n':
|
||||
return U8X8_MSG_GPIO_MENU_NEXT;
|
||||
case 'p':
|
||||
return U8X8_MSG_GPIO_MENU_PREV;
|
||||
case 's':
|
||||
return U8X8_MSG_GPIO_MENU_SELECT;
|
||||
case 'h':
|
||||
return U8X8_MSG_GPIO_MENU_HOME;
|
||||
case 'x':
|
||||
exit(0);
|
||||
default:
|
||||
puts("press n, p, s, h or x");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#else /* __unix__ */
|
||||
|
||||
|
||||
#define U8X8_DEBOUNCE_WAIT 2
|
||||
/* do debounce and return a GPIO msg which indicates the event */
|
||||
/* returns 0, if there is no event */
|
||||
#if defined(__GNUC__) && !defined(__CYGWIN__)
|
||||
# pragma weak u8x8_GetMenuEvent
|
||||
#endif
|
||||
uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
|
||||
{
|
||||
uint8_t pin_state;
|
||||
uint8_t result_msg = 0; /* invalid message, no event */
|
||||
|
||||
pin_state = u8x8_read_pin_state(u8x8);
|
||||
|
||||
/* States A, B, C & D are encoded in the upper 4 bit*/
|
||||
switch(u8x8->debounce_state)
|
||||
{
|
||||
case 0x00: /* State A, default state */
|
||||
if ( u8x8->debounce_default_pin_state != pin_state )
|
||||
{
|
||||
//u8x8->debounce_last_pin_state = pin_state;
|
||||
u8x8->debounce_state = 0x010 + U8X8_DEBOUNCE_WAIT;
|
||||
}
|
||||
break;
|
||||
case 0x10: /* State B */
|
||||
//if ( u8x8->debounce_last_pin_state != pin_state )
|
||||
if ( u8x8->debounce_default_pin_state == pin_state )
|
||||
{
|
||||
u8x8->debounce_state = 0x00; /* back to state A */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* keypress detected */
|
||||
u8x8->debounce_last_pin_state = pin_state;
|
||||
//result_msg = U8X8_MSG_GPIO_MENU_NEXT;
|
||||
u8x8->debounce_state = 0x020 + U8X8_DEBOUNCE_WAIT; /* got to state C */
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x20: /* State C */
|
||||
if ( u8x8->debounce_last_pin_state != pin_state )
|
||||
{
|
||||
u8x8->debounce_state = 0x00; /* back to state A */
|
||||
}
|
||||
else
|
||||
{
|
||||
u8x8->debounce_state = 0x030; /* got to state D */
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x30: /* State D */
|
||||
/* wait until key release */
|
||||
if ( u8x8->debounce_default_pin_state == pin_state )
|
||||
{
|
||||
u8x8->debounce_state = 0x00; /* back to state A */
|
||||
result_msg = U8X8_MSG_GPIO(u8x8_find_first_diff(u8x8->debounce_default_pin_state, u8x8->debounce_last_pin_state)+U8X8_PIN_OUTPUT_CNT);
|
||||
}
|
||||
else
|
||||
{
|
||||
//result_msg = U8X8_MSG_GPIO_MENU_NEXT;
|
||||
// maybe implement autorepeat here
|
||||
}
|
||||
break;
|
||||
default:
|
||||
u8x8->debounce_state--; /* count down, until there is a valid state */
|
||||
break;
|
||||
}
|
||||
return result_msg;
|
||||
}
|
||||
|
||||
#endif /* __unix__ */
|
||||
203
Middlewares/u8g2Lib/src/u8x8_display.c
Normal file
203
Middlewares/u8g2Lib/src/u8x8_display.c
Normal file
@ -0,0 +1,203 @@
|
||||
/*
|
||||
|
||||
u8x8_display.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
Abstraction layer for the graphics controller.
|
||||
Main goal is the placement of a 8x8 pixel block (tile) on the display.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
|
||||
/*==========================================*/
|
||||
/* internal library function */
|
||||
|
||||
/*
|
||||
this is a helper function for the U8X8_MSG_DISPLAY_SETUP_MEMORY function.
|
||||
It can be called within the display callback function to carry out the usual standard tasks.
|
||||
|
||||
*/
|
||||
void u8x8_d_helper_display_setup_memory(u8x8_t *u8x8, const u8x8_display_info_t *display_info)
|
||||
{
|
||||
/* 1) set display info struct */
|
||||
u8x8->display_info = display_info;
|
||||
u8x8->x_offset = u8x8->display_info->default_x_offset;
|
||||
}
|
||||
|
||||
/*
|
||||
this is a helper function for the U8X8_MSG_DISPLAY_INIT function.
|
||||
It can be called within the display callback function to carry out the usual standard tasks.
|
||||
|
||||
*/
|
||||
void u8x8_d_helper_display_init(u8x8_t *u8x8)
|
||||
{
|
||||
/* 2) apply port directions to the GPIO lines and apply default values for the IO lines*/
|
||||
u8x8_gpio_Init(u8x8);
|
||||
u8x8_cad_Init(u8x8); /* this will also call U8X8_MSG_BYTE_INIT, byte init will NOT call GPIO_INIT */
|
||||
|
||||
/* 3) do reset */
|
||||
u8x8_gpio_SetReset(u8x8, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
|
||||
u8x8_gpio_SetReset(u8x8, 0);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
|
||||
u8x8_gpio_SetReset(u8x8, 1);
|
||||
u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->post_reset_wait_ms);
|
||||
}
|
||||
|
||||
/*==========================================*/
|
||||
/* official functions */
|
||||
|
||||
uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr)
|
||||
{
|
||||
u8x8_tile_t tile;
|
||||
tile.x_pos = x;
|
||||
tile.y_pos = y;
|
||||
tile.cnt = cnt;
|
||||
tile.tile_ptr = tile_ptr;
|
||||
return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, 1, (void *)&tile);
|
||||
}
|
||||
|
||||
/* should be implemented as macro */
|
||||
void u8x8_SetupMemory(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SETUP_MEMORY, 0, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
This will just init the display interface, compared to InitDisplay, it will not issue a reset and also not upload the init code.
|
||||
Comparison:
|
||||
Call u8x8_InitInterface u8x8_InitDisplay
|
||||
Init Interface yes yes
|
||||
Reset Display no yes
|
||||
Upload Display Init Code no yes
|
||||
|
||||
u8x8_InitInterface() is an alternative function to u8x8_InitDisplay(). Do not call both.
|
||||
|
||||
*/
|
||||
void u8x8_InitInterface(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8_gpio_Init(u8x8);
|
||||
u8x8_cad_Init(u8x8); /* this will also call U8X8_MSG_BYTE_INIT, byte init will NOT call GPIO_INIT */
|
||||
}
|
||||
|
||||
/*
|
||||
This will sent the display init message to the display.
|
||||
The display itself will then call u8x8_d_helper_display_init() from above. This includes:
|
||||
GPIO Init (set port directions)
|
||||
BYTE init (part of CAD init: which may set some levels)
|
||||
CAD init (which will set things like I2C default address)
|
||||
Issue a reset to the display: This will usually turn off the display
|
||||
Additonally each display will set the init code to the display, which will also turn of the display in most cases (Arduino code disable power save mode later)
|
||||
|
||||
Actually this procedure should be better called InitInterfaceAndDisplay, because it actually does both.
|
||||
(actually u8x8_InitInterface() is not called directly but only u8x8_gpio_Init and u8x8_cad_Init which
|
||||
in turn is called by u8x8_InitInterface())
|
||||
|
||||
|
||||
InitDisplay is called by the Arduino begin() function
|
||||
|
||||
In some cases it is not required to init the display (for example if the display is already running, but the controller comes out of deep sleep mode).
|
||||
Then InitDisplay can be skipped, but u8x8_InitInterface() (== u8x8_gpio_Init() and u8x8_cad_Init()) need to be executed.
|
||||
|
||||
*/
|
||||
void u8x8_InitDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_INIT, 0, NULL); /* this will call u8x8_d_helper_display_init() and send the init seqence to the display */
|
||||
/* u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_FLIP_MODE, 0, NULL); */ /* It would make sense to call flip mode 0 here after U8X8_MSG_DISPLAY_INIT */
|
||||
}
|
||||
|
||||
void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_POWER_SAVE, is_enable, NULL);
|
||||
}
|
||||
|
||||
void u8x8_SetFlipMode(u8x8_t *u8x8, uint8_t mode)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_FLIP_MODE, mode, NULL);
|
||||
}
|
||||
|
||||
void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_CONTRAST, value, NULL);
|
||||
}
|
||||
|
||||
void u8x8_RefreshDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_REFRESH, 0, NULL);
|
||||
}
|
||||
|
||||
void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf)
|
||||
{
|
||||
u8x8_tile_t tile;
|
||||
uint8_t h;
|
||||
|
||||
tile.x_pos = 0;
|
||||
tile.cnt = 1;
|
||||
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
|
||||
|
||||
h = u8x8->display_info->tile_height;
|
||||
tile.y_pos = 0;
|
||||
do
|
||||
{
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
|
||||
tile.y_pos++;
|
||||
} while( tile.y_pos < h );
|
||||
}
|
||||
|
||||
void u8x8_ClearDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
u8x8_ClearDisplayWithTile(u8x8, buf);
|
||||
}
|
||||
|
||||
void u8x8_FillDisplay(u8x8_t *u8x8)
|
||||
{
|
||||
uint8_t buf[8] = { 255, 255, 255, 255, 255, 255, 255, 255 };
|
||||
u8x8_ClearDisplayWithTile(u8x8, buf);
|
||||
}
|
||||
|
||||
void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line)
|
||||
{
|
||||
uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
u8x8_tile_t tile;
|
||||
if ( line < u8x8->display_info->tile_height )
|
||||
{
|
||||
tile.x_pos = 0;
|
||||
tile.y_pos = line;
|
||||
tile.cnt = 1;
|
||||
tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
|
||||
u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
|
||||
}
|
||||
}
|
||||
19833
Middlewares/u8g2Lib/src/u8x8_fonts.c
Normal file
19833
Middlewares/u8g2Lib/src/u8x8_fonts.c
Normal file
File diff suppressed because it is too large
Load Diff
50
Middlewares/u8g2Lib/src/u8x8_gpio.c
Normal file
50
Middlewares/u8g2Lib/src/u8x8_gpio.c
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
|
||||
u8x8_gpio.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
|
||||
void u8x8_gpio_call(u8x8_t *u8x8, uint8_t msg, uint8_t arg)
|
||||
{
|
||||
u8x8->gpio_and_delay_cb(u8x8, msg, arg, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
void u8x8_gpio_Delay(u8x8_t *u8x8, uint8_t msg, uint8_t dly)
|
||||
{
|
||||
u8x8->gpio_and_delay_cb(u8x8, msg, dly, NULL);
|
||||
}
|
||||
*/
|
||||
123
Middlewares/u8g2Lib/src/u8x8_input_value.c
Normal file
123
Middlewares/u8g2Lib/src/u8x8_input_value.c
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
|
||||
u8x8_input_value.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
/*
|
||||
return:
|
||||
0: value is not changed (HOME/Break Button pressed)
|
||||
1: value has been updated
|
||||
*/
|
||||
|
||||
uint8_t u8x8_UserInterfaceInputValue(u8x8_t *u8x8, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post)
|
||||
{
|
||||
uint8_t height;
|
||||
uint8_t y;
|
||||
uint8_t width;
|
||||
uint8_t x;
|
||||
uint8_t local_value = *value;
|
||||
uint8_t r;
|
||||
uint8_t event;
|
||||
|
||||
/* calculate overall height of the input value box */
|
||||
height = 1; /* button line */
|
||||
height += u8x8_GetStringLineCnt(title);
|
||||
|
||||
/* calculate offset from top */
|
||||
y = 0;
|
||||
if ( height < u8x8_GetRows(u8x8) )
|
||||
{
|
||||
y = u8x8_GetRows(u8x8);
|
||||
y -= height;
|
||||
y /= 2;
|
||||
}
|
||||
|
||||
/* calculate offset from left for the label */
|
||||
x = 0;
|
||||
width = u8x8_GetUTF8Len(u8x8, pre);
|
||||
width += digits;
|
||||
width += u8x8_GetUTF8Len(u8x8, post);
|
||||
if ( width < u8x8_GetCols(u8x8) )
|
||||
{
|
||||
x = u8x8_GetCols(u8x8);
|
||||
x -= width;
|
||||
x /= 2;
|
||||
}
|
||||
|
||||
/* render */
|
||||
u8x8_ClearDisplay(u8x8); /* required, because not everything is filled */
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title);
|
||||
x += u8x8_DrawUTF8(u8x8, x, y, pre);
|
||||
u8x8_DrawUTF8(u8x8, x+digits, y, post);
|
||||
u8x8_SetInverseFont(u8x8, 1);
|
||||
|
||||
/* event loop */
|
||||
u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
|
||||
for(;;)
|
||||
{
|
||||
event = u8x8_GetMenuEvent(u8x8);
|
||||
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
|
||||
{
|
||||
*value = local_value;
|
||||
r = 1;
|
||||
break;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
|
||||
{
|
||||
r = 0;
|
||||
break;
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
|
||||
{
|
||||
if ( local_value >= hi )
|
||||
local_value = lo;
|
||||
else
|
||||
local_value++;
|
||||
u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
|
||||
{
|
||||
if ( local_value <= lo )
|
||||
local_value = hi;
|
||||
else
|
||||
local_value--;
|
||||
u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
|
||||
}
|
||||
}
|
||||
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
return r;
|
||||
}
|
||||
152
Middlewares/u8g2Lib/src/u8x8_message.c
Normal file
152
Middlewares/u8g2Lib/src/u8x8_message.c
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
|
||||
u8x8_message.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
uint8_t u8x8_draw_button_line(u8x8_t *u8x8, uint8_t y, uint8_t w, uint8_t cursor, const char *s)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t cnt;
|
||||
uint8_t total;
|
||||
uint8_t d;
|
||||
uint8_t x;
|
||||
cnt = u8x8_GetStringLineCnt(s);
|
||||
|
||||
/* calculate the width of the button */
|
||||
total = 0;
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
total += u8x8_GetUTF8Len(u8x8, u8x8_GetStringLineStart(i, s));
|
||||
}
|
||||
total += (cnt-1); /* had one space between the buttons */
|
||||
|
||||
/* calculate the left offset */
|
||||
d = 0;
|
||||
if ( total < w )
|
||||
{
|
||||
d = w;
|
||||
d -= total;
|
||||
d /= 2;
|
||||
}
|
||||
|
||||
/* draw the buttons */
|
||||
x = d;
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
if ( i == cursor )
|
||||
u8x8_SetInverseFont(u8x8, 1);
|
||||
|
||||
x+=u8x8_DrawUTF8(u8x8, x, y, u8x8_GetStringLineStart(i, s));
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
x+=u8x8_DrawUTF8(u8x8, x, y, " ");
|
||||
}
|
||||
|
||||
/* return the number of buttons */
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*
|
||||
title1: Multiple lines,separated by '\n'
|
||||
title2: A single line/string which is terminated by '\0' or '\n' . "title2" accepts the return value from u8x8_GetStringLineStart()
|
||||
title3: Multiple lines,separated by '\n'
|
||||
buttons: one more more buttons separated by '\n' and terminated with '\0'
|
||||
*/
|
||||
|
||||
uint8_t u8x8_UserInterfaceMessage(u8x8_t *u8x8, const char *title1, const char *title2, const char *title3, const char *buttons)
|
||||
{
|
||||
uint8_t height;
|
||||
uint8_t y;
|
||||
uint8_t cursor = 0;
|
||||
uint8_t button_cnt;
|
||||
uint8_t event;
|
||||
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
|
||||
/* calculate overall height of the message box */
|
||||
height = 1; /* button line */
|
||||
height += u8x8_GetStringLineCnt(title1);
|
||||
if ( title2 != NULL )
|
||||
height ++;
|
||||
height += u8x8_GetStringLineCnt(title3);
|
||||
|
||||
/* calculate offset from top */
|
||||
y = 0;
|
||||
if ( height < u8x8_GetRows(u8x8) )
|
||||
{
|
||||
y = u8x8_GetRows(u8x8);
|
||||
y -= height;
|
||||
y /= 2;
|
||||
}
|
||||
|
||||
/* draw message box */
|
||||
|
||||
u8x8_ClearDisplay(u8x8); /* required, because not everything is filled */
|
||||
|
||||
y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title1);
|
||||
if ( title2 != NULL )
|
||||
{
|
||||
u8x8_DrawUTF8Line(u8x8, 0, y, u8x8_GetCols(u8x8), title2);
|
||||
y++;
|
||||
}
|
||||
y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title3);
|
||||
|
||||
button_cnt = u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
event = u8x8_GetMenuEvent(u8x8);
|
||||
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
|
||||
return cursor+1;
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
|
||||
break;
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
|
||||
{
|
||||
cursor++;
|
||||
if ( cursor >= button_cnt )
|
||||
cursor = 0;
|
||||
u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
|
||||
{
|
||||
if ( cursor == 0 )
|
||||
cursor = button_cnt;
|
||||
cursor--;
|
||||
u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
173
Middlewares/u8g2Lib/src/u8x8_selection_list.c
Normal file
173
Middlewares/u8g2Lib/src/u8x8_selection_list.c
Normal file
@ -0,0 +1,173 @@
|
||||
/*
|
||||
|
||||
u8x8_selection_list.c
|
||||
|
||||
selection list with scroll option
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
/*
|
||||
increase the cursor position
|
||||
*/
|
||||
void u8sl_Next(u8sl_t *u8sl)
|
||||
{
|
||||
u8sl->current_pos++;
|
||||
if ( u8sl->current_pos >= u8sl->total )
|
||||
{
|
||||
u8sl->current_pos = 0;
|
||||
u8sl->first_pos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( u8sl->first_pos + u8sl->visible <= u8sl->current_pos + 1 )
|
||||
{
|
||||
u8sl->first_pos = u8sl->current_pos - u8sl->visible + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void u8sl_Prev(u8sl_t *u8sl)
|
||||
{
|
||||
if ( u8sl->current_pos == 0 )
|
||||
{
|
||||
u8sl->current_pos = u8sl->total - 1;
|
||||
u8sl->first_pos = 0;
|
||||
if ( u8sl->total > u8sl->visible )
|
||||
u8sl->first_pos = u8sl->total - u8sl->visible;
|
||||
}
|
||||
else
|
||||
{
|
||||
u8sl->current_pos--;
|
||||
if ( u8sl->first_pos > u8sl->current_pos )
|
||||
u8sl->first_pos = u8sl->current_pos;
|
||||
}
|
||||
}
|
||||
|
||||
void u8x8_DrawSelectionList(u8x8_t *u8x8, u8sl_t *u8sl, u8x8_sl_cb sl_cb, const void *aux)
|
||||
{
|
||||
uint8_t i;
|
||||
for( i = 0; i < u8sl->visible; i++ )
|
||||
{
|
||||
sl_cb(u8x8, u8sl, i+u8sl->first_pos, aux);
|
||||
}
|
||||
}
|
||||
|
||||
/* selection list with string line */
|
||||
void u8x8_sl_string_line_cb(u8x8_t *u8x8, u8sl_t *u8sl, uint8_t idx, const void *aux)
|
||||
{
|
||||
const char *s;
|
||||
uint8_t row;
|
||||
/* calculate offset from display upper border */
|
||||
row = u8sl->y;
|
||||
|
||||
/* calculate target pos */
|
||||
row += idx;
|
||||
row -= u8sl->first_pos;
|
||||
|
||||
/* check whether this is the current cursor line */
|
||||
if ( idx == u8sl->current_pos )
|
||||
u8x8_SetInverseFont(u8x8, 1);
|
||||
else
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
|
||||
/* get the line from the array */
|
||||
s = u8x8_GetStringLineStart(idx, (const char *)aux);
|
||||
|
||||
/* draw the line */
|
||||
if ( s == NULL )
|
||||
s = "";
|
||||
u8x8_DrawUTF8Line(u8x8, u8sl->x, row, u8x8_GetCols(u8x8), s);
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
title: NULL for no title, valid str for title line. Can contain mutliple lines, separated by '\n'
|
||||
start_pos: default position for the cursor (starts with 1)
|
||||
sl: string list (list of strings separated by \n)
|
||||
returns 0 if user has pressed the home key
|
||||
returns the selected line+1 if user has pressed the select key (e.g. 1 for the first line)
|
||||
*/
|
||||
uint8_t u8x8_UserInterfaceSelectionList(u8x8_t *u8x8, const char *title, uint8_t start_pos, const char *sl)
|
||||
{
|
||||
u8sl_t u8sl;
|
||||
uint8_t event;
|
||||
uint8_t title_lines;
|
||||
|
||||
if ( start_pos > 0 )
|
||||
start_pos--;
|
||||
|
||||
u8sl.visible = u8x8_GetRows(u8x8);
|
||||
u8sl.total = u8x8_GetStringLineCnt(sl);
|
||||
u8sl.first_pos = 0;
|
||||
u8sl.current_pos = start_pos;
|
||||
u8sl.x = 0;
|
||||
u8sl.y = 0;
|
||||
|
||||
|
||||
//u8x8_ClearDisplay(u8x8); /* not required because all is 100% filled */
|
||||
u8x8_SetInverseFont(u8x8, 0);
|
||||
|
||||
if ( title != NULL )
|
||||
{
|
||||
title_lines = u8x8_DrawUTF8Lines(u8x8, u8sl.x, u8sl.y, u8x8_GetCols(u8x8), title);
|
||||
u8sl.y+=title_lines;
|
||||
u8sl.visible-=title_lines;
|
||||
}
|
||||
|
||||
if ( u8sl.current_pos >= u8sl.total )
|
||||
u8sl.current_pos = u8sl.total-1;
|
||||
|
||||
|
||||
u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
|
||||
|
||||
for(;;)
|
||||
{
|
||||
event = u8x8_GetMenuEvent(u8x8);
|
||||
if ( event == U8X8_MSG_GPIO_MENU_SELECT )
|
||||
return u8sl.current_pos+1;
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_HOME )
|
||||
return 0;
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
|
||||
{
|
||||
u8sl_Next(&u8sl);
|
||||
u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
|
||||
}
|
||||
else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
|
||||
{
|
||||
u8sl_Prev(&u8sl);
|
||||
u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
147
Middlewares/u8g2Lib/src/u8x8_setup.c
Normal file
147
Middlewares/u8g2Lib/src/u8x8_setup.c
Normal file
@ -0,0 +1,147 @@
|
||||
/*
|
||||
|
||||
u8x8_setup.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
/* universal dummy callback, which will be default for all callbacks */
|
||||
uint8_t u8x8_dummy_cb(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
|
||||
{
|
||||
/* the dummy callback will not handle any message and will fail for all messages */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const u8x8_display_info_t u8x8_null_display_info =
|
||||
{
|
||||
/* chip_enable_level = */ 0,
|
||||
/* chip_disable_level = */ 1,
|
||||
|
||||
/* post_chip_enable_wait_ns = */ 0,
|
||||
/* pre_chip_disable_wait_ns = */ 0,
|
||||
/* reset_pulse_width_ms = */ 0,
|
||||
/* post_reset_wait_ms = */ 0,
|
||||
/* sda_setup_time_ns = */ 0,
|
||||
/* sck_pulse_width_ns = */ 0, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
|
||||
/* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
|
||||
/* spi_mode = */ 0, /* active high, rising edge */
|
||||
/* i2c_bus_clock_100kHz = */ 4,
|
||||
/* data_setup_time_ns = */ 0,
|
||||
/* write_pulse_width_ns = */ 0,
|
||||
/* tile_width = */ 1, /* 8x8 */
|
||||
/* tile_hight = */ 1,
|
||||
/* default_x_offset = */ 0,
|
||||
/* flipmode_x_offset = */ 0,
|
||||
/* pixel_width = */ 8,
|
||||
/* pixel_height = */ 8
|
||||
};
|
||||
|
||||
|
||||
/* a special null device */
|
||||
uint8_t u8x8_d_null_cb(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
|
||||
{
|
||||
switch(msg)
|
||||
{
|
||||
case U8X8_MSG_DISPLAY_SETUP_MEMORY:
|
||||
u8x8_d_helper_display_setup_memory(u8x8, &u8x8_null_display_info);
|
||||
break;
|
||||
case U8X8_MSG_DISPLAY_INIT:
|
||||
u8x8_d_helper_display_init(u8x8);
|
||||
break;
|
||||
}
|
||||
/* the null device callback will succeed for all messages */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Description:
|
||||
Setup u8x8
|
||||
Args:
|
||||
u8x8 An empty u8x8 structure
|
||||
*/
|
||||
void u8x8_SetupDefaults(u8x8_t *u8x8)
|
||||
{
|
||||
u8x8->display_info = NULL;
|
||||
u8x8->display_cb = u8x8_dummy_cb;
|
||||
u8x8->cad_cb = u8x8_dummy_cb;
|
||||
u8x8->byte_cb = u8x8_dummy_cb;
|
||||
u8x8->gpio_and_delay_cb = u8x8_dummy_cb;
|
||||
u8x8->is_font_inverse_mode = 0;
|
||||
//u8x8->device_address = 0;
|
||||
u8x8->utf8_state = 0; /* also reset by u8x8_utf8_init */
|
||||
u8x8->bus_clock = 0; /* issue 769 */
|
||||
u8x8->i2c_address = 255;
|
||||
u8x8->debounce_default_pin_state = 255; /* assume all low active buttons */
|
||||
|
||||
#ifdef U8X8_USE_PINS
|
||||
{
|
||||
uint8_t i;
|
||||
for( i = 0; i < U8X8_PIN_CNT; i++ )
|
||||
u8x8->pins[i] = U8X8_PIN_NONE;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Description:
|
||||
Setup u8x8 and assign the callback function. The dummy
|
||||
callback "u8x8_dummy_cb" can be used, if no callback is required.
|
||||
This setup will not communicate with the display itself.
|
||||
Use u8x8_InitDisplay() to send the startup code to the Display.
|
||||
Args:
|
||||
u8x8 An empty u8x8 structure
|
||||
display_cb Display/controller specific callback function
|
||||
cad_cb Display controller specific communication callback function
|
||||
byte_cb Display controller/communication specific callback funtion
|
||||
gpio_and_delay_cb Environment specific callback function
|
||||
|
||||
*/
|
||||
void u8x8_Setup(u8x8_t *u8x8, u8x8_msg_cb display_cb, u8x8_msg_cb cad_cb, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
|
||||
{
|
||||
/* setup defaults and reset pins to U8X8_PIN_NONE */
|
||||
u8x8_SetupDefaults(u8x8);
|
||||
|
||||
/* setup specific callbacks */
|
||||
u8x8->display_cb = display_cb;
|
||||
u8x8->cad_cb = cad_cb;
|
||||
u8x8->byte_cb = byte_cb;
|
||||
u8x8->gpio_and_delay_cb = gpio_and_delay_cb;
|
||||
|
||||
/* setup display info */
|
||||
u8x8_SetupMemory(u8x8);
|
||||
}
|
||||
|
||||
170
Middlewares/u8g2Lib/src/u8x8_string.c
Normal file
170
Middlewares/u8g2Lib/src/u8x8_string.c
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
|
||||
u8x8_string.c
|
||||
|
||||
string line procedures
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
uint8_t u8x8_GetStringLineCnt(const char *str)
|
||||
{
|
||||
char e;
|
||||
uint8_t line_cnt = 1;
|
||||
if ( str == NULL )
|
||||
return 0;
|
||||
for(;;)
|
||||
{
|
||||
e = *str;
|
||||
if ( e == '\0' )
|
||||
break;
|
||||
str++;
|
||||
if ( e == '\n' )
|
||||
line_cnt++;
|
||||
}
|
||||
return line_cnt;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Assumes strings, separated by '\n' in "str".
|
||||
Returns the string at index "line_idx". First strng has line_idx = 0
|
||||
Example:
|
||||
Returns "xyz" for line_idx = 1 with str = "abc\nxyz"
|
||||
Support both UTF8 and normal strings.
|
||||
*/
|
||||
const char *u8x8_GetStringLineStart(uint8_t line_idx, const char *str )
|
||||
{
|
||||
char e;
|
||||
uint8_t line_cnt = 1;
|
||||
|
||||
if ( line_idx == 0 )
|
||||
return str;
|
||||
|
||||
for(;;)
|
||||
{
|
||||
e = *str;
|
||||
if ( e == '\0' )
|
||||
break;
|
||||
str++;
|
||||
if ( e == '\n' )
|
||||
{
|
||||
if ( line_cnt == line_idx )
|
||||
return str;
|
||||
line_cnt++;
|
||||
}
|
||||
}
|
||||
return NULL; /* line not found */
|
||||
}
|
||||
|
||||
/* copy until first '\n' or '\0' in str */
|
||||
/* Important: There is no string overflow check, ensure */
|
||||
/* that the destination buffer is large enough */
|
||||
void u8x8_CopyStringLine(char *dest, uint8_t line_idx, const char *str)
|
||||
{
|
||||
if ( dest == NULL )
|
||||
return;
|
||||
str = u8x8_GetStringLineStart( line_idx, str );
|
||||
if ( str != NULL )
|
||||
{
|
||||
for(;;)
|
||||
{
|
||||
if ( *str == '\n' || *str == '\0' )
|
||||
break;
|
||||
*dest = *str;
|
||||
dest++;
|
||||
str++;
|
||||
}
|
||||
}
|
||||
*dest = '\0';
|
||||
}
|
||||
|
||||
/*
|
||||
Draw a string
|
||||
Extend the string to size "w"
|
||||
Center the string within "w"
|
||||
return the size of the string
|
||||
|
||||
*/
|
||||
uint8_t u8x8_DrawUTF8Line(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t w, const char *s)
|
||||
{
|
||||
uint8_t d, lw;
|
||||
uint8_t cx, dx;
|
||||
|
||||
d = 0;
|
||||
|
||||
lw = u8x8_GetUTF8Len(u8x8, s);
|
||||
if ( lw < w )
|
||||
{
|
||||
d = w;
|
||||
d -=lw;
|
||||
d /= 2;
|
||||
}
|
||||
|
||||
cx = x;
|
||||
dx = cx + d;
|
||||
while( cx < dx )
|
||||
{
|
||||
u8x8_DrawUTF8(u8x8, cx, y, " ");
|
||||
cx++;
|
||||
}
|
||||
cx += u8x8_DrawUTF8(u8x8, cx, y, s);
|
||||
dx = x + w;
|
||||
while( cx < dx )
|
||||
{
|
||||
u8x8_DrawUTF8(u8x8, cx, y, " ");
|
||||
cx++;
|
||||
}
|
||||
cx -= x;
|
||||
return cx;
|
||||
}
|
||||
|
||||
/*
|
||||
draw several lines at position x,y.
|
||||
lines are stored in s and must be separated with '\n'.
|
||||
lines can be centered with respect to "w"
|
||||
if s == NULL nothing is drawn and 0 is returned
|
||||
returns the number of lines in s
|
||||
*/
|
||||
uint8_t u8x8_DrawUTF8Lines(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t w, const char *s)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t cnt;
|
||||
cnt = u8x8_GetStringLineCnt(s);
|
||||
for( i = 0; i < cnt; i++ )
|
||||
{
|
||||
u8x8_DrawUTF8Line(u8x8, x, y, w, u8x8_GetStringLineStart(i, s));
|
||||
y++;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
77
Middlewares/u8g2Lib/src/u8x8_u16toa.c
Normal file
77
Middlewares/u8g2Lib/src/u8x8_u16toa.c
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
|
||||
u8x8_u16toa.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
const char *u8x8_u16toap(char * dest, uint16_t v)
|
||||
{
|
||||
uint8_t pos;
|
||||
uint8_t d;
|
||||
uint16_t c;
|
||||
c = 10000;
|
||||
for( pos = 0; pos < 5; pos++ )
|
||||
{
|
||||
d = '0';
|
||||
while( v >= c )
|
||||
{
|
||||
v -= c;
|
||||
d++;
|
||||
}
|
||||
dest[pos] = d;
|
||||
c /= 10;
|
||||
}
|
||||
dest[5] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* v = value, d = number of digits */
|
||||
const char *u8x8_u16toa(uint16_t v, uint8_t d)
|
||||
{
|
||||
static char buf[6];
|
||||
d = 5-d;
|
||||
return u8x8_u16toap(buf, v) + d;
|
||||
}
|
||||
|
||||
const char *u8x8_utoa(uint16_t v)
|
||||
{
|
||||
const char *s = u8x8_u16toa(v, 5);
|
||||
while( *s == '0' )
|
||||
s++;
|
||||
if ( *s == '\0' )
|
||||
s--;
|
||||
return s;
|
||||
}
|
||||
67
Middlewares/u8g2Lib/src/u8x8_u8toa.c
Normal file
67
Middlewares/u8g2Lib/src/u8x8_u8toa.c
Normal file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
|
||||
u8x8_u8toa.c
|
||||
|
||||
Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
|
||||
|
||||
Copyright (c) 2016, olikraus@gmail.com
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include "u8x8.h"
|
||||
|
||||
static const unsigned char u8x8_u8toa_tab[3] = { 100, 10, 1 } ;
|
||||
const char *u8x8_u8toap(char * dest, uint8_t v)
|
||||
{
|
||||
uint8_t pos;
|
||||
uint8_t d;
|
||||
uint8_t c;
|
||||
for( pos = 0; pos < 3; pos++ )
|
||||
{
|
||||
d = '0';
|
||||
c = *(u8x8_u8toa_tab+pos);
|
||||
while( v >= c )
|
||||
{
|
||||
v -= c;
|
||||
d++;
|
||||
}
|
||||
dest[pos] = d;
|
||||
}
|
||||
dest[3] = '\0';
|
||||
return dest;
|
||||
}
|
||||
|
||||
/* v = value, d = number of digits */
|
||||
const char *u8x8_u8toa(uint8_t v, uint8_t d)
|
||||
{
|
||||
static char buf[4];
|
||||
d = 3-d;
|
||||
return u8x8_u8toap(buf, v) + d;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user