mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
util: Add MIN and MAX macros
This commit is contained in:
parent
c06593e864
commit
83a34ff925
@ -40,8 +40,6 @@
|
||||
#include "u2f_knownapps.h"
|
||||
#include "u2f.h"
|
||||
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
|
||||
// About 1/2 Second according to values used in protect.c
|
||||
#define U2F_TIMEOUT (800000/2)
|
||||
#define U2F_OUT_PKT_BUFFER_LEN 128
|
||||
|
19
oled.c
19
oled.c
@ -306,9 +306,6 @@ void oledDrawStringRight(int x, int y, const char* text)
|
||||
oledDrawString(x, y, text);
|
||||
}
|
||||
|
||||
#define max(X,Y) ((X) > (Y) ? (X) : (Y))
|
||||
#define min(X,Y) ((X) < (Y) ? (X) : (Y))
|
||||
|
||||
void oledDrawBitmap(int x, int y, const BITMAP *bmp)
|
||||
{
|
||||
for (int i = 0; i < bmp->width; i++) {
|
||||
@ -327,10 +324,10 @@ void oledDrawBitmap(int x, int y, const BITMAP *bmp)
|
||||
*/
|
||||
void oledInvert(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
x1 = max(x1, 0);
|
||||
y1 = max(y1, 0);
|
||||
x2 = min(x2, OLED_WIDTH - 1);
|
||||
y2 = min(y2, OLED_HEIGHT - 1);
|
||||
x1 = MAX(x1, 0);
|
||||
y1 = MAX(y1, 0);
|
||||
x2 = MIN(x2, OLED_WIDTH - 1);
|
||||
y2 = MIN(y2, OLED_HEIGHT - 1);
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
oledInvertPixel(x,y);
|
||||
@ -343,10 +340,10 @@ void oledInvert(int x1, int y1, int x2, int y2)
|
||||
*/
|
||||
void oledBox(int x1, int y1, int x2, int y2, bool set)
|
||||
{
|
||||
x1 = max(x1, 0);
|
||||
y1 = max(y1, 0);
|
||||
x2 = min(x2, OLED_WIDTH - 1);
|
||||
y2 = min(y2, OLED_HEIGHT - 1);
|
||||
x1 = MAX(x1, 0);
|
||||
y1 = MAX(y1, 0);
|
||||
x2 = MIN(x2, OLED_WIDTH - 1);
|
||||
y2 = MIN(y2, OLED_HEIGHT - 1);
|
||||
for (int x = x1; x <= x2; x++) {
|
||||
for (int y = y1; y <= y2; y++) {
|
||||
set ? oledDrawPixel(x, y) : oledClearPixel(x, y);
|
||||
|
4
util.h
4
util.h
@ -25,6 +25,10 @@
|
||||
#include <libopencm3/cm3/scb.h>
|
||||
#include <libopencm3/cm3/vector.h>
|
||||
|
||||
// Statement expressions make these macros side-effect safe
|
||||
#define MIN(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); _a > _b ? _a : _b; })
|
||||
#define MAX(a, b) ({ typeof(a) _a = (a); typeof(b) _b = (b); _a > _b ? _a : _b; })
|
||||
|
||||
void delay(uint32_t wait);
|
||||
|
||||
// converts uint32 to hexa (8 digits)
|
||||
|
Loading…
Reference in New Issue
Block a user