Code Monkey home page Code Monkey logo

stm32lib's Introduction

stm32 mcu common using library

Dependencies

  • stm32 standard library
  • ....

Usage

usart usage

#include "usart.h"


/**
*
* @brief: handle usart rx , this function will be called when usart's rx interrupt occured
* @args: ucByte, the data byte that usart received
* @returns: None
*
*/
void
_HandleUsartRX(uint8_t ucByte)
{
    // fill here with you logical code
}


int
main(void)
{
    // The detail parameters signature, please refer to usart.h
    usart_Initiate(USART1,  115200, 1);
    // register usart rx interrupt callback
    usart_RegisterRXCallback(USART1, _HandleUsartRX)
    while(1)
    {
        usart_Printf(USART1, "hello world %s", "stm32");
    }
    return 0;
}

key usage

implementation principle

this key implementation's fundamental principle is checking key's state
in the stm32 timer's updating ISR , when key is down, the user registered
callback function will be called with 'pxKeyEvent' as function's parameter.

#include "key.h"


void
_HandleKeyEvent(KeyEvent_t * pxEvent)
{
    switch(pxEvent->ulId)
    {
        case 0:
            // handle key 0 event
            if(pxEvent->eType == SHORT_PRESSED)
            {
	        // when key 0 is short time  pressed
            }
            else if(pxEvent->eType == LONG_PRESSED)
            {
                // when key 0 is long time pressed
            }
            else 
            {
                // when key0 is long time pressing
            }
            break;
        case 1:
            // handle key 1 event
            break;
        case 2:
            // handle key 2 event
            break;
    }
}



int 
main(void)
{

    // GPIOA.8 ===> id = 0, key 0
    // GPIOA.9 ===> id = 1, key 1
    // GPIOA.10 ===> id = 2, key 2
    key_Initiate(GPIOA, 0x01 << 10 | 0x01 << 9 | 0x01 << 8);
    // register event callback function ,this callback function be called
    //  when key event occured, this function will be called,
    key_RegisterEventCallback(_HandleKeyEvent);
    while(1)
    {
        // other stuff
    }
    return 0;
}

rtc lib usage

#include "rtc.h"

DateTime_t dt;

// initiate the begining datetime
dt.ulSecond = 40;
dt.ucMin = 41;
dt.ucHour = 15;
dt.ucDay = 4;
dt.ucMonth = 6;
dt.ulYear = 2017;

// initiate stm32 RTC 
// note that this function must be called firstly, whenever \
//   you want to stm32's RTC hardware 
rtc_Initiate(&dt);

// get the current datetime
rtc_GetDateTime(&dt);

// set the current datetime;
dt.ucHour = 19;
rtc_SetDateTime(&dt);

// set RTC alarm datetime
dt.ucHourt = 20;
rtc_SetAlarmDateTime(&dt);

// this function will called when RTC's alarm interrupt occurrs
static void 
_HandleRTCAlarm(DateTime_t * pxDT)
{
   // write your logical code here
}

// when you write your RTC alarm ISR callback, you need to \ 
//   register it by calling following function
rtc_RegisterAlarmCallback(_HandleRTCAlarm);


// this helper function can convert your datetime to seconds
rtc_DT2Seconds(&dt);

stm32lib's People

Contributors

free-free avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.