Merge pull request #88 from lancaster-university/ticker_improvements

Ticker improvements
This commit is contained in:
James Devine 2016-02-02 21:50:20 +00:00
commit c9702aacb0
3 changed files with 12 additions and 6 deletions

View File

@ -262,7 +262,7 @@
// Selects the minimum permissable brightness level for the device
// in the region of 0 (off) to 255 (full brightness)
#ifndef MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS
#define MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS 4
#define MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS 1
#endif
// Selects the maximum permissable brightness level for the device

View File

@ -14,7 +14,7 @@
"author": "Joe Finney <j.finney@lancaster.ac.uk (mailto:j.finney@lancaster.ac.uk) >",
"homepage": "https://developer.mbed.org/teams/Lancaster-University/code/microbit/",
"dependencies": {
"mbed-classic": "~0.0.4",
"mbed-classic": "lancaster-university/mbed-classic#microbit_hfclk",
"ble": "lancaster-university/BLE_API#v2.5.0+mb",
"ble-nrf51822": "lancaster-university/nrf51822#v2.5.0+mb3",
"nrf51-sdk": "lancaster-university/nrf51-sdk#v2.2.0+mb2"
@ -22,4 +22,4 @@
"extraIncludes": [
"inc"
]
}
}

View File

@ -8,7 +8,7 @@
#include "MicroBitMatrixMaps.h"
#include "nrf_gpio.h"
const float timings[MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH] = {0.000010, 0.000047, 0.000094, 0.000187, 0.000375, 0.000750, 0.001500, 0.003000};
const int timings[MICROBIT_DISPLAY_GREYSCALE_BIT_DEPTH] = {1, 23, 70, 163, 351, 726, 1476, 2976};
/**
* Constructor.
@ -147,7 +147,7 @@ void MicroBitDisplay::render()
//timer does not have enough resolution for brightness of 1. 23.53 us
if(brightness != MICROBIT_DISPLAY_MAXIMUM_BRIGHTNESS && brightness > MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS)
renderTimer.attach_us(this, &MicroBitDisplay::renderFinish, (((brightness * 1000) / (MICROBIT_DISPLAY_MAXIMUM_BRIGHTNESS)) * uBit.getTickPeriod()));
renderTimer.attach_us(this, &MicroBitDisplay::renderFinish, (((brightness * 950) / (MICROBIT_DISPLAY_MAXIMUM_BRIGHTNESS)) * uBit.getTickPeriod()));
//this will take around 23us to execute
if(brightness <= MICROBIT_DISPLAY_MINIMUM_BRIGHTNESS)
@ -222,7 +222,13 @@ void MicroBitDisplay::renderGreyscale()
greyscaleBitMsk <<= 1;
renderTimer.attach(this,&MicroBitDisplay::renderGreyscale, timings[timingCount++]);
if(timingCount < 3)
{
wait_us(timings[timingCount++]);
renderGreyscale();
return;
}
renderTimer.attach_us(this,&MicroBitDisplay::renderGreyscale, timings[timingCount++]);
}
/**