1
0
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:
Saleem Rashid 2017-12-09 13:30:15 +00:00 committed by Pavol Rusnak
parent c06593e864
commit 83a34ff925
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 12 additions and 13 deletions

View File

@ -40,8 +40,6 @@
#include "u2f_knownapps.h" #include "u2f_knownapps.h"
#include "u2f.h" #include "u2f.h"
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
// About 1/2 Second according to values used in protect.c // About 1/2 Second according to values used in protect.c
#define U2F_TIMEOUT (800000/2) #define U2F_TIMEOUT (800000/2)
#define U2F_OUT_PKT_BUFFER_LEN 128 #define U2F_OUT_PKT_BUFFER_LEN 128

19
oled.c
View File

@ -306,9 +306,6 @@ void oledDrawStringRight(int x, int y, const char* text)
oledDrawString(x, y, 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) void oledDrawBitmap(int x, int y, const BITMAP *bmp)
{ {
for (int i = 0; i < bmp->width; i++) { 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) void oledInvert(int x1, int y1, int x2, int y2)
{ {
x1 = max(x1, 0); x1 = MAX(x1, 0);
y1 = max(y1, 0); y1 = MAX(y1, 0);
x2 = min(x2, OLED_WIDTH - 1); x2 = MIN(x2, OLED_WIDTH - 1);
y2 = min(y2, OLED_HEIGHT - 1); y2 = MIN(y2, OLED_HEIGHT - 1);
for (int x = x1; x <= x2; x++) { for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) { for (int y = y1; y <= y2; y++) {
oledInvertPixel(x,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) void oledBox(int x1, int y1, int x2, int y2, bool set)
{ {
x1 = max(x1, 0); x1 = MAX(x1, 0);
y1 = max(y1, 0); y1 = MAX(y1, 0);
x2 = min(x2, OLED_WIDTH - 1); x2 = MIN(x2, OLED_WIDTH - 1);
y2 = min(y2, OLED_HEIGHT - 1); y2 = MIN(y2, OLED_HEIGHT - 1);
for (int x = x1; x <= x2; x++) { for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) { for (int y = y1; y <= y2; y++) {
set ? oledDrawPixel(x, y) : oledClearPixel(x, y); set ? oledDrawPixel(x, y) : oledClearPixel(x, y);

4
util.h
View File

@ -25,6 +25,10 @@
#include <libopencm3/cm3/scb.h> #include <libopencm3/cm3/scb.h>
#include <libopencm3/cm3/vector.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); void delay(uint32_t wait);
// converts uint32 to hexa (8 digits) // converts uint32 to hexa (8 digits)